相关疑难解决方法(0)

操作参数命名

使用提供的默认路由,我被迫将参数命名为"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)

c# asp.net-mvc asp.net-mvc-routing

30
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net-mvc ×1

asp.net-mvc-routing ×1

c# ×1