当前位置: 代码迷 >> ASP.NET >> ASP.NET MVC2 中的URL传值有关问题
  详细解决方案

ASP.NET MVC2 中的URL传值有关问题

热度:8493   发布时间:2013-02-25 00:00:00.0
ASP.NET MVC2 中的URL传值问题
一个URL,例如 /Product/Del/10
其中,Product 是 controller
Del 是 action
10 是 action 的唯一参数

对应的action是这样写的:

[HttpGet]
public ActionResult Del(int? productid){
// do something here.
}

上面的 HTTPGet 加不加都无法获取到 productid 的值,也就是 10

URL 改成下面这种模式就能接受到

/Product/Del/?productid=10

请高手指点一下怎么解决?

------解决方案--------------------------------------------------------
应该是你Global里面的路由配置不对吧
------解决方案--------------------------------------------------------
假设楼主用的是自动生成的路由

public ActionResult Del(int? productid)

->

public ActionResult Del(int? id)