开发者

Do the parameter names in ASP.NET MVC routes need to match those in their corresponding actions?

开发者 https://www.devze.com 2022-12-16 10:46 出处:网络
Do the parameter names in ASP.NET MVC routes need to match those in their corresp开发者_开发问答onding actions, and if so, why?Yes, bacause of convention (over configuration). It\'s simplier and faste

Do the parameter names in ASP.NET MVC routes need to match those in their corresp开发者_开发问答onding actions, and if so, why?


Yes, bacause of convention (over configuration). It's simplier and faster do develop application in that way: that's the power of ASP.NET MVC.


Indeed. The RouteData collection's "Values" dictionary will be scanned for the key/value pair whose name matches the parameter name.

In the following action method the "month" parameter would be automatically populated according to the {month} portion of the incoming URL route:

public ActionResult Index(string month) {
    if( month == "1" )
        //Happy New Year!
}


1) Yes. 2) How else would they match? The name is all you have, in both cases.


No, not when you create your own defaultmodelbinder and/or controlleractioninvoker

0

精彩评论

暂无评论...
验证码 换一张
取 消