asp.net-mvc-routing

mvc3 Routes setup as id, id2 id3

不羁的心 提交于 2019-12-01 10:53:54
问题 I have the following area routes setup. context.MapRoute( "Admin_default3", "Admin/{controller}/{action}/{id}/{id2}/{id3}", new { action = "Index" } ); context.MapRoute( "Admin_default2", "Admin/{controller}/{action}/{id}/{id2}", new { action = "Index"} ); context.MapRoute( "Admin_default", "Admin/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional } ); When a controller action is hit I do something like the following where I place the params into readable variable

Display View in folder without Controller or Action in ASP.net MVC

瘦欲@ 提交于 2019-12-01 10:45:32
I would like to display the view in the folder if no controller/action matches. For example www.site.com/Home/Index, if I have the normal default route {controller}/{action}/{id} then I need a HomeController with method Index. And there is a folder in Views folder called Home and the file Index.cshtml If i try www.site.com/About/Index i need to create the AboutController and the method index. But I have just the folder About and file Index.cshtml. I would like that if the default route does not match but I have a Folder and a File in the Views folder that match the patern: {controller} is the

MVC Routing template to represent infinite self-referential hierarchical category structure

给你一囗甜甜゛ 提交于 2019-12-01 10:44:08
I have a product category table to represent a hierarchical category structure, a typical Parent-Child relationship table in the database. Fill it with Guitar Center's data as an example: If you render them to a page with <ul> and <li> : Texts in blue are the URLs I would like to generate. For any given category, the link consists of its slug and its parents' slugs. Note that the example I listed only has 2 parent-child levels. In theory, with the self-referential structure, any child could have infinite parents. Questions: How to set up routing template to achieve that? If the routing

Attribute vs Conventional Routing

▼魔方 西西 提交于 2019-12-01 09:38:43
问题 Q1: So this article says attribute routing is more favourable than conventional routing for api versioning. It's not clear to me the reasons behind such claim because to me in order to support these: /api/v1/products /api/v2/products all you need to do is to define two routes: routes.MapHttpRoute("V1", "api/v1/products", new {controller = "V1Controller", action = "ListProducts"}); routes.MapHttpRoute("V2", "api/v2/products", new {controller = "V2Controller", action = "ListProducts"}); Can

Subfolder in Controllers ASP.NET MVC [duplicate]

折月煮酒 提交于 2019-12-01 09:34:13
This question already has an answer here: Route controller that is in a sub folder 2 answers In my Controllers folder i want to have a subfolder called Admin. When i go to http://localhost:port/Admin/Login/ it says the page could not be found. RouteConfig.cs using System.Web.Mvc; using System.Web.Routing; namespace ICT4Events { public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id =

ASP.NET MVC : Empty ActionLinks appearing

泪湿孤枕 提交于 2019-12-01 09:26:09
问题 I'm using a default route, so that I don't need to specify the controller. routes.MapRoute( "Default", "{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); With this, I can create URLs like myapp.com/Customers rather than myapp.com/Home/Customers When I test locally, everything is fine. When I upload a live version, any links generated with Html.ActionLink are empty. I know I'm using Html.ActionLink correctly, because it works fine locally: // Title

Display View in folder without Controller or Action in ASP.net MVC

删除回忆录丶 提交于 2019-12-01 08:32:00
问题 I would like to display the view in the folder if no controller/action matches. For example www.site.com/Home/Index, if I have the normal default route {controller}/{action}/{id} then I need a HomeController with method Index. And there is a folder in Views folder called Home and the file Index.cshtml If i try www.site.com/About/Index i need to create the AboutController and the method index. But I have just the folder About and file Index.cshtml. I would like that if the default route does

form get with value in mvc route

半腔热情 提交于 2019-12-01 08:22:48
问题 I am working with mvc4 and have a field where a user can enter some text in to an input field which gets passed to the url and redirect to another page eg. /search/<> My form is as follows but redirects as query string. <form class="search" action="@Url.Action("Index", "Search")"> <div> <input name="q" value="" type="search" /> <input type="image" name="btn" value="search" src="@Url.Content("/image1.jpg")" /> </div> </form> Any idea how I could alter my form to pass the inputed value to input

ASP.NET MVC 2 RC2 Routing - How to clear low-level values when using ActionLink to refer to a higher level?

陌路散爱 提交于 2019-12-01 08:02:18
问题 [NOTE: I'm using ASP.NET MVC2 RC2.] I have URLs like this: /customers/123/orders/456/items/index /customers/123/orders/456/items/789/edit My routing table lists the most-specific routes first, so I've got: // customers/123/orders/456/items/789/edit routes.MapRoute( "item", // Route name "customers/{customerId}/orders/{orderId}/items/{itemId}/{action}", // URL with parameters new { controller = "Items", action = "Details" }, // Parameter defaults new { customerId = @"\d+", orderId = @"\d+",

ASP.NET route with arbitrary number of key-value pairs - is it possible?

点点圈 提交于 2019-12-01 07:32:57
I'd like to handle URLs like this: /Id/Key1/Value1/Key2/Value2/Key3/Value3/ Right now, I have set up a rule like this: /{id}/{*parameters} The parameters object is passed as a single string to all the actions that are involved in forming the response. This does work, but I have a few problems with it: Each action must resolve the string for itself. I've, of course, made an extension method that turns the string to a Dictionary<string, string> , but I'd prefer it if the dispatching mechanism gave my methods a Dictionary<string, string> directly - or, better yet, the actual pairs as separate