asp.net-mvc-routing

ASP.NET MVC Routing , Html.BeginForm

心不动则不痛 提交于 2020-01-14 13:31:32
问题 <% using (Html.BeginForm("SearchByZip", "Dealer", new { zip = ""}, FormMethod.Get)) { %> <div> <input type="text" class="padLeft" name="Zip" id="Zip" style="width: 200px" /> <input type="submit" class="btnFind" value="Find" /> </div> <% } %> This gives me the url "Dealer/SearchByZip?Zip=12345" I would like to end up with this: "Dealer/Zip/12345" (if I manually type in the url "Dealer/Zip/12345" it returns the right results, but when I click in submit it comes up with "Dealer/SearchByZip?Zip

How to map querystring to action method parameters in MVC?

元气小坏坏 提交于 2020-01-14 09:42:48
问题 I have a url http://localhost/Home/DomSomething?t=123&s=TX and i want to route this URL to the following action method public class HomeController { public ActionResult DoSomething(int taxYear,string state) { // do something here } } since the query string names does not match with action method's parameter name, request is not routing to the action method. If i change the url (just for testing) to http://localhost/Home/DomSomething?taxYear=123&state=TX then its working. (But i dont have

How to map querystring to action method parameters in MVC?

牧云@^-^@ 提交于 2020-01-14 09:42:28
问题 I have a url http://localhost/Home/DomSomething?t=123&s=TX and i want to route this URL to the following action method public class HomeController { public ActionResult DoSomething(int taxYear,string state) { // do something here } } since the query string names does not match with action method's parameter name, request is not routing to the action method. If i change the url (just for testing) to http://localhost/Home/DomSomething?taxYear=123&state=TX then its working. (But i dont have

How to map querystring to action method parameters in MVC?

只谈情不闲聊 提交于 2020-01-14 09:42:06
问题 I have a url http://localhost/Home/DomSomething?t=123&s=TX and i want to route this URL to the following action method public class HomeController { public ActionResult DoSomething(int taxYear,string state) { // do something here } } since the query string names does not match with action method's parameter name, request is not routing to the action method. If i change the url (just for testing) to http://localhost/Home/DomSomething?taxYear=123&state=TX then its working. (But i dont have

Ambiguous Actions

醉酒当歌 提交于 2020-01-14 04:12:09
问题 Is there any way to have multiple actions with different parameters? I've seen it using the HttpPost verbs flag, but it doesn't seem to work for me in other places. The current request for action List on controller type FoldersController` is ambiguous between the following action methods. public ActionResult List() { //... } public ActionResult List(DateTime start) { // ... } public ActionResult List(string key) { // .... } Trying this Route Paramter I found on ... I'm still a bit confused

.net Core - Default controller is not loading when Route attribute is used

夙愿已清 提交于 2020-01-13 08:45:16
问题 A new .net core web application project comes with the following route configuration: app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); If you replace this with app.UseMvc() and add appropriate Route attributes for both HomeController and its actions (Index, About, Contact, Error), it would still work. Since we're not specifying a default route, the default view (Home/Index) will not be rendered if you hit http://localhost:25137/

asp.net mvc routing: how to use default action but non-default parameter?

孤人 提交于 2020-01-12 12:49:26
问题 I'm rewriting the question, as the answers so far show me that I have not defined it good enough. I'll leave the original question for reference below. When you set up your routing you can specify defaults for different url/route parts. Let's consider example that VS wizard generates: routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "DefaultPage", action = "Index", id = UrlParameter.Optional } // Parameter defaults In this

asp.net mvc. Routing and Url building

蹲街弑〆低调 提交于 2020-01-12 06:19:06
问题 Does any body knows how to hide some parameters in url? For example you have a url parameter "culture". It can be "en, fr, it". By default your site renders in "en" culture and we don't wont to show default culture in the URL but in cases of other cultures parameter "culture" must appear in URL. http://myrendersite.net/barbikueue http://myrendersite.net/fr/barbikueue This is same pages in different cultures. How to do what basing on default asp.net mvc routing system? 回答1: This will help: ASP

.NET 4.5 MVC RouteCollection.LowercaseUrls breaks when using Area

醉酒当歌 提交于 2020-01-10 17:29:14
问题 A new property to RouteCollection was added with .NET Framework 4.5: http://msdn.microsoft.com/en-us/library/system.web.routing.routecollection.lowercaseurls.aspx This works great, until you add an Area to your project. All Urls are propercase again. Any ideas why this happens? It's simple to reproduce: Create new MVC 4 Internet Application (.NET 4.5) Start RouteConfig.RegisterRoutes function with: routes.LowercaseUrls = true; Run the project and you'll see all generated Urls are now

How to ignore current route values when generating links?

一曲冷凌霜 提交于 2020-01-10 08:50:10
问题 The question is similar to asp.net mvc Html.ActionLink() keeping route value I don't want, but with a twist that makes it more complex. Starting from a default new MVC3 app, I change the routes to: routes.MapRoute( "r1", // Route name "{controller}/{id}/{action}" ); routes.MapRoute( "r2", // Route name "{controller}/{action}" ); Notice that the id comes before the action in the first. Then in Home\Index.cshtml, I add: @Url.Action("Index") @Url.Action("Index", new { id = "blah" }) @Url.Action(