![](/img/trans.png)
[英]How do I use String.Replace method inside a custom ASP.NET MVC Route?
[英]How do I construct my action method for a specific route Asp.Net MVC
我有兩條路線要嘗試使用,例如
www.mysite.com/Rate/Student/Event/123
www.mysite.com/Rate/Teacher/Event/1234
routes.MapRoute(
name: "Rate",
url: "Rate/Student/Event/{id}"
);
routes.MapRoute(
name: "Rate",
url: "Rate/Teacher/Event/{id}"
);
如何構造動作方法?
這是我的費率控制器中的內容
public ActionResult Student(int id)
{
return View();
}
public ActionResult Teacher(int id)
{
return View();
}
您已經設置了路由以匹配URL,但是尚未告訴MVC將請求發送到哪里。 MapRoute通過使用路由值來工作 ,該路由值可以默認為特定值,也可以通過URL傳遞。 但是,您都不做。
注意: MVC中需要
controller
和action
路線值。
routes.MapRoute(
name: "Rate",
url: "Rate/Student/Event/{id}",
defaults: new { controller = "Rate", action = "Student" }
);
routes.MapRoute(
name: "Rate",
url: "Rate/Teacher/Event/{id}",
defaults: new { controller = "Rate", action = "Teacher" }
);
routes.MapRoute(
name: "Rate",
url: "{controller}/{action}/Event/{id}"
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.