Mantorok
Mantorok

Reputation: 5276

Maintaining the query string in ASP.Net MVC

Just beginning my journey in ASP.Net MVC and I have a query about something before I dig myself in too deep.

I have a table, which is paged, and I have 2 controls above the table:

What I need to achieve is that if the user changes the order or adds a filter I fire of an AJAX call to my action like such: /Membership/Users?sort=value&filter=value&page=pagenumber. So my controller action is:

   // GET Membership/Users?sort=&filter=&page=
   public ActionResult Users(string sort, string filter, string page)

So I have 3 questions:

Thanks

Upvotes: 3

Views: 754

Answers (1)

David Neale
David Neale

Reputation: 17048

You could define a new route in the format Membership/Users/{sort}/{filter}/{page}.

routes.MapRoute(
        "MembershipList",                                              
        "Membership/Users/{sort}/{filter}/{page}",             
        new { controller = "Membership", action = "Users", sort = "", filter = "", page = "" }
    );

However, if the parameters are optional then I would suggest you leave it as is and don't define a route.

As you are passing through strings then they will simply be passed as null if for some reason no query strings are passed, your action should handle this and still render a view.

Upvotes: 2

Related Questions