0
私はBlog
という名前のコントローラを持っています。 私はこのような作用を有する:アクションが2つのパラメータを持つときに経路を見つけることができません - Asp.Net MVC
[Route("{code:int}/{title?}")]
public virtual ActionResult Index(int code, string title)
{
var postModel = _blogService.Get(code.ToUrlDecription());
return View(postModel);
}
私はこれらのURLを入力し、それらのすべてが見つからないを返しました:
localhost:7708/Blog/index/12/post-title
。localhost:7708/Blog/index/12
;localhost:7708/Blog/12/post-title
。
私は以下のようなルートを書き込もうとしましたが、結果は同じであった:
routes.MapRoute(
name: "showblogpost", url: "{controller}/{action}/{code}/{title}",
defaults: new {
controller = "Blog",
action = "Index",
title = UrlParameter.Optional
},
namespaces:new string[] { "Web.Controllers" }
);
[ルート]属性が必要な理由は何ですか? – saniokazzz
私は多分 'ルート属性'とすることができると思う – Rahimi