A problem with overloading an action in ASP.NET MVC
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
精彩评论