asp.net-mvc-routing

RouteCollection' doesn't contain a definition for 'MapMvcAttributeRoutes

久未见 提交于 2019-12-20 01:40:15
问题 I just had to downgrade my ASP.Net 4.5.2 application to ASP.Net 4.0. Of course this brings problems with it, like references that are not installed correct. I solved some of them already, but I can't get my head around an error: CS106 'RouteCollection' does not contain a definition for 'MapMvcAttributeRoutes' and no extension method 'MapMvcAttributeRoutes' accepting a first argument of type 'RouteCollection' could be found public class RouteConfig { public static void RegisterRoutes

Create Route for a specific URL without changing the URL with MVC

蓝咒 提交于 2019-12-19 19:52:10
问题 I have a MVC Web Application that runs on www.domain.com and I need to configure a different URL binding for another domain www.domain2.com for the same web application. The new domain www.domain2.com will have to return a specific Controller Action View like /Category/Cars : routes.MapRoute( name: "www.domain2.com", url: "www.domain2.com", defaults: new { controller = "Category", action = "Cars", id = UrlParameter.Optional } ); How can I achieve this without changing the URL, so the visitor

MVC5 : Attribute Routing Precedence Among Controllers

旧巷老猫 提交于 2019-12-19 18:56:33
问题 I am using the Attribute Routing from MVC5 in my controllers. Question: Is there a way to control attribute routing precedence among controllers? Consider the following [Route("home/{action=index}/{username?}")] public class HomeController : Controller { [Route("home/index/{username?}", Order = 1)] [Route("home/{username?}", Order = 2)] [Route("{username?}", Order = 3)] public ActionResult Index() { // ... bunch of stuff } } Base on the code above, HomeController.Index() action method should

C# MVC 4 ControllerName attribute

故事扮演 提交于 2019-12-19 17:48:05
问题 I'm working on providing friendly names for my MVC 4 controllers and I want to do something like the [ActionName="My-Friendly-Name"] style, but for the whole controller. I couldn't find any information about such an attribute, so how would I go about doing that? Also, will I need to add a new MapRoute to handle it? EDIT: For example, I'd like to route the following url: http://mysite.com/my-reports/Details/5 be routed to the following controller: [ControllerClass="my-reports"] // This

Appending ?param= to mvc routes

妖精的绣舞 提交于 2019-12-19 17:44:10
问题 Some MVC sites have querystring params appended to the route Url (of which I noticed StackOverflow does), such as: https://stackoverflow.com/questions/tagged/java ?page=9802&sort=newest&pagesize=15 What are the advantages of having the parameters as more conventional ?querystring params, rather than /param/values/ ? Also, how are these params appended to routes that have been set up? I'm familiar with setting up mvc routes with params like "users/details/{id}" etc. but don't know how to

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

大城市里の小女人 提交于 2019-12-19 10:36:11
问题 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

How to Route /About to /Home/About

心已入冬 提交于 2019-12-19 10:24:13
问题 I am just getting started with ASP.NET MVC and it's great! However, I don't quite understand setting up routes. How do I route ~/About to ~/Home/About? /Views/Home/About.aspx I would like to be able to access it with /Home/About or just /About 回答1: If you want to explicity setup a route for it, you can do something like this: routes.MapRoute( "AboutRoute", "About", new { controller = "Home", action = "About" } // Parameter defaults ); I think thats what you want to do? I.e. have /About

MVC 3 use different controllers based on request parameters

╄→гoц情女王★ 提交于 2019-12-19 04:59:50
问题 I've been scouring the web for a solution for this the past couple days and I'm not finding much. Hopefully I'm not using the right terminology and it's an easy thing to do. I would like to use a path like: /{projectId} And have a place somewhere early on in the life-cycle where I have access to the route value dictionary that I can query a database or a session object to get the controller name to use for this request. Then be able to specify the controller to use route.Values["controller"]

MVC 3 use different controllers based on request parameters

ぐ巨炮叔叔 提交于 2019-12-19 04:59:06
问题 I've been scouring the web for a solution for this the past couple days and I'm not finding much. Hopefully I'm not using the right terminology and it's an easy thing to do. I would like to use a path like: /{projectId} And have a place somewhere early on in the life-cycle where I have access to the route value dictionary that I can query a database or a session object to get the controller name to use for this request. Then be able to specify the controller to use route.Values["controller"]

MVC3 + WordPress IIS Url Rewriting Rules

寵の児 提交于 2019-12-19 04:09:21
问题 I have a ASP.NET MVC3 website located at http://mydomain.com/mymvcapp/. However, the root of the webiste (mydomain.com) contains a WordPress site running PHP. Therefore, I put the following IIS URL Rewrite rule to allow WordPress to function correctly via its rewriting mechanisms: <rewrite> <rules> <rule name="wordpress" patternSyntax="Wildcard"> <match url="*" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType=