Search page MVC routing (hidden action, no slashes, like SO)?

You don't need two routes because you're providing search parameters as query string. Just have one search route: routes. MapRoute( "Search", "Search", new { controller = "Search", action = "Search" } ) Then write this controller action public ActionResult Search(int?

Type, string q) { var defaultType = type. HasValue? Type.

Value : 1; if (string. IsNullOrEmpty(q)) { // perform search } // do other stuff } The body of this method greatly depends on the search condition whether you require both parameters when you search for stuff or just q and you have some default for type Remember that page indexing can be done just the same way Using strong type parameters (validation wise) You could of course create a class that could be validated, but property names should reflect that of the query string. So you'd either have a class: public class SearchTerms { public int?

Type { get; set; } public string q { get; set; } } And use the same request with equally named query variables as you do now, or have a clean class and adjust your request: public class SearchTerms { public int? Type { get; set; } public string Query { get; set; } } http://domain.com/Search?Type=1&Query=search+text.

You don't need two routes because you're providing search parameters as query string. Just have one search route: routes. MapRoute( "Search", "Search", new { controller = "Search", action = "Search" } ); Then write this controller action public ActionResult Search(int?

Type, string q) { var defaultType = type. HasValue? Type.

Value : 1; if (string. IsNullOrEmpty(q)) { // perform search } // do other stuff } The body of this method greatly depends on the search condition whether you require both parameters when you search for stuff or just q and you have some default for type. Remember that page indexing can be done just the same way.

Using strong type parameters (validation wise) You could of course create a class that could be validated, but property names should reflect that of the query string. So you'd either have a class: public class SearchTerms { public int? Type { get; set; } public string q { get; set; } } And use the same request with equally named query variables as you do now, or have a clean class and adjust your request: public class SearchTerms { public int?

Type { get; set; } public string Query { get; set; } } http://domain.com/Search?Type=1&Query=search+text.

Works nicely in this manner. But if I use a model binder though (to bind a model that wraps "type" and "q") what do I specify for the route? – Matt0 Feb 22 at 8:55 Nothing to specify in route, but in Action you have to be careful about Model validation.

You can include or exclude Model properties using Bind attribute – Adeel Feb 22 at 9:21 Route would stay the same, but query variable names would have to adjust to class property names. Lemme write some code. – Robert Koritnik Feb 22 at 9:22 Using the model works!

Thanks Robert. – Matt0 Feb 22 at 9:41.

You don't need two routes because you're providing search parameters as query string. The body of this method greatly depends on the search condition whether you require both parameters when you search for stuff or just q and you have some default for type. Remember that page indexing can be done just the same way.

You could of course create a class that could be validated, but property names should reflect that of the query string.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions