Lan*_*don 30 c# asp.net-mvc asp.net-mvc-routing
使用提供的默认路由,我被迫将参数命名为"id".这对我的许多控制器动作来说都很好,但我想在某些地方使用一些更好的变量命名.我可以使用某种属性,以便在操作签名中包含更有意义的变量名称吗?
// Default Route:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
// Action Signature:
public ActionResult ByAlias(string alias)
{
// Because the route specifies "id" and this action takes an "alias", nothing is bound
}
Run Code Online (Sandbox Code Playgroud)
Lev*_*evi 48
使用[Bind]属性:
public ActionResult ByAlias([Bind(Prefix = "id")] string alias) {
// your code here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11234 次 |
| 最近记录: |