How to use QueryString
How can I have different URL ids like www.somewebsite.com/index?theidentifier=34 only in ASP.N开发者_开发问答ET MVC not Webforms.
Well, for what purpose? Just to access the value? All querystring values can be routed to params in the action method like:
public ActionResult index(int? theidentifier)
{
//process value
}
Or, you can use the QueryString collection as mentioned above, I think it's via this.RequestContext.HttpContext.Request.QueryString.
If you want to handle your routing in ASP.NET MVC, then you can open Global.asax and add calling of routes.MapRoute in RegisterRoutes method.
The default routing configuration is {controller}/{action}/{id} => ex: http://localhost/Home/Index/3 , controller = HomeController, Action=About, id=3.
You may add something like :
routes.MapRoute( "NewRoute", // Route name "Index/{id}", // URL with parameters new { controller = "Home", action = "Index",id=1 } // Parameter defaults );
so http://localhost/Index/3 will be accepted
Remember to add these code above the default route configuration, because ASP.NET will search for the first matching route
精彩评论