开发者

A problem with overloading an action in ASP.NET MVC

开发者 https://www.devze.com 2023-01-28 19:41 出处:网络
how should look the Global.asax file and my Controller\'s action to process 2 types of the URL: http://.../Search

how should look the Global.asax file and my Controller's action to process 2 types of the URL:

http://.../Search
http://.../Search?q=abc&p=1&...&...&...& (many 开发者_运维技巧parameters, do I have to list all 
                                          of them in the Global.asax file ?)

?


No, you don't have to list them all in your global.asax file, just have them as optional parameters in your action.

e.g.

public ActionResult Search(string q, int page = 1, string country = "", etc etc)

If you're not able to use default values, just make them nullable.

e.g.

public ActionResult Search(string q, int? page, string country, etc etc)

Savvy?

HTHs,
Charles

0

精彩评论

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