XIJUN-LEE

神马都不懂……

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
HTML helper中参数何时会是路由参数,何时又会是query string?
 
@Html.ActionLink("Edit", "Edit", new { idnumber = item.OrderTypeID }) 
 
在形如上述的html helper中,第三个参数是routeValues,如果第三个参数并没有出现在App_Start中的路由文件RouteConfig.cs中(url: "{controller}/{action}/{id}/{actionid}"),则第三个参数会以query string 出现在url中,即http://XXX/ordertypes/Edit?idnumber=1.需要指出的是,routeValue是可以不出现在url的路由定义中的,没有出现过的,一律将以query string 出现在url中。
 
 
@Html.ActionLink("Edit", "Edit", new { id = item.OrderTypeID }) 
 
但若第三个参数出现在url: "{controller}/{action}/{id}/{actionid}"定义中,则会作为路由参数出现在url中,即http://XXX/ordertypes/Edit/1
(默认路由为ordertypes控制器中edit方法,参数id=1)
 
总之,路由参数都会以上述两种形式被写入到url中,传递给controller,但必须保证views中html helper的参数名要与controller中相应的actionMethod中的参数名一致,这样才能正确地将view中数据传递给controller。
posted on 2015-03-25 15:21  XIJUN-LEE  阅读(279)  评论(0编辑  收藏  举报