mvc Html.BeginForm different URL schema

A form with FormMethod.Get will always post back the values of its form controls as query string values. A browser cannot generate a url based on your route configurations because they are server side code. If you really wanted to generate /Stations/View/f2cecc62-7c8c-498d-b6b6-60d48a862c1c, then you could use javascript/jquery to build your own url and redirect @using … Read more

How to use an Area in ASP.NET Core

In order to include an Area in an ASP.NET Core app, first we need to include a conventional route in the Startup.cs file (It’s best to place it before any non-area route): In Startup.cs/Configure method: app.UseMvc(routes => { routes.MapRoute(“areaRoute”, “{area:exists}/{controller=Admin}/{action=Index}/{id?}”); routes.MapRoute( name: “default”, template: “{controller=Home}/{action=Index}/{id?}”); }); Then make a folder named Areas in the app … Read more

How to get RouteData by URL?

I used Moq to determine what members of HttpContextBase are used in GetRouteData(). They are: Request AppRelativeCurrentExecutionFilePath PathInfo Request.AppRelativeCurrentExecutionFilePath should return path with ~, what I exactly need, so utility class may be like this one: public static class RouteUtils { public static RouteData GetRouteDataByUrl(string url) { return RouteTable.Routes.GetRouteData(new RewritedHttpContextBase(url)); } private class RewritedHttpContextBase : … Read more

How can I create a friendly URL in ASP.NET MVC?

There are two steps to solve this problem. First, create a new route or change the default route to accept an additional parameter: routes.MapRoute( “Default”, // Route name “{controller}/{action}/{id}/{ignoreThisBit}”, new { controller = “Home”, action = “Index”, id = “”, ignoreThisBit = “”} // Parameter defaults ) Now you can type whatever you want to … Read more

ASP.NET MVC custom routing for search

Option 1 Of course you always can choose the way of /car/search/?vendor=Toyota&color=Red&model=Corola and I think it will be good for you. routes.MapRoute( “CarSearch”, “car/search”, new { controller = “car”, action = “search” } ); You can get params from Request.Params in action in this case. Option 2 Or you can define params in the routing … Read more