what is the best way to create an asp.net mvc controller action with lots of variables
i have a URL
http://www.mysite.com/RunRep开发者_JS百科ort
and a controller action:
[CompressFilter]
public ActionResult RunReport(int field1, int field2, int field3, int field4, int field5, int field6, . . .)
so to run the query with a filter, you wind of having to do something like this:
http://www.mysite.com/RunReport/0/0/0/0/0/1/0. . . .
is there a better way of doing this without such a ugly url and routing?
i want to be able to have persistent URL that maps to specific queries.
You don't have to have these fields in the Route. You can have them in a query string like so:
RunReport?field3=1
You can then combine them into a POCO class like so
public class MyModel
{
int? Field1 { get; set; }
int? Field2 { get; set; }
int? Field3 { get; set; }
}
This makes your Fields optional and your Model class can have some smarts in it too, that can determine which report you want to run for example.
And controller action
public ActionResult RunReport(MyModel model)
This will work with either GET or POST (or whatever other verb you want to use
精彩评论