我有一个非常基本的 ASP.Net MVC 项目,我想在我的控制器操作之一上使用 id 参数名称。从我读过的所有内容来看,这应该不是问题,但由于某种原因,使用 id 参数名称无法获取从查询字符串中提取的值,但如果我将其更改为任何其他不同的名称,它将起作用。
我的 global.asx 中只有一条路线
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
我的控制器方法是:
public ActionResult Confirm(string id)
{
....
}
网址为http://mysite/customer/confirm/abcd http://mysite/customer/confirm/abcd作品。网址为http://mysite/customer/confirm?id=abcd http://mysite/customer/confirm?id=abcd fails.
如果我将控制器方法更改为:
public ActionResult Confirm(string customerID)
{
....
}
然后是一个 URLhttp://mysite/customer/confirm?customerID=abcd http://mysite/customer/confirm?customerID=abcd works.
在 ASP.Net MVC 查询字符串中使用“id”作为参数有什么特别之处吗?
更新:将 id 从 1234 更改为 abcd,我的 id 实际上是字符串。