asp.net-mvc-routing

Exceptions in System.Web.Routing.RouteCollection.GetRouteData

穿精又带淫゛_ 提交于 2019-12-06 01:05:52
问题 I've been getting two exceptions at random times in my asp.net mvc code running on iis7: Exception type: InvalidOperationException Exception message: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.List'1.Enumerator.MoveNextRare() at System.Collections.Generic.List'1.Enumerator.MoveNext() at System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext)

MVC Routing without controller in the url

删除回忆录丶 提交于 2019-12-06 00:39:24
问题 How do I configure ASP.NET MVC 3 routing so it doesn’t shown the controller in the url? Here's my routes routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); routes.MapRoute( "HomeActions", "{action}", new { action= "AboutUs" } ); I need url: mysite.com/AboutUs But I have mysite.com/Home/AboutUs 回答1: I would be very specific about the url that you want to route. And place it above the default route. routes

Render bootstrap dropdown menu with in c# MVC3 Html.ActionLink

空扰寡人 提交于 2019-12-06 00:33:34
Therefore I faced an issue with MVC ActionLink and bootstrap dropdown. I succeeded with simple menu extension where I passed such a parameters like strings and one bool. But now I am trying to make my own extension which could generate Bootstrap Dropdown and add selected css class to parent of the dropdown - "ONEofTHEdropdownITEMSselected" - when one of those items in dropdown is selected (when selecting dropdown item it routes to different controller there fore can be few or more controllers): <a href="#" class="dropdown-toggle ONEofTHEdropdownITEMSselected" data-toggle="dropdown">Dropdown <b

Virtual Directory App within a Asp.net MVC app

北慕城南 提交于 2019-12-06 00:14:54
I am having issues trying to host screwturn wiki as a virtual directory application within my current domain. the domain is hosted as something.com and the wiki would look like something.com/wiki when i browse to something.com/wiki I get Could not load file or assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. Why is the virtual directory falling back to the root application. Shouldn't it be its own application boundary? I have also added to the root mvc app routes.IgnoreRoute("{

Getting area, controller and action names inside filter attributes

拈花ヽ惹草 提交于 2019-12-05 21:52:31
I have global attribute in which i need to know the area, controller and action. I can't use RawUrl due to routes (inside area registration and attribute routing). I have followed the following two approaches but in both cases, my area is coming back as null. When i use a route then i get the area name just fine. Why is my area null when i do redirecttoaction or url.action or type the url manually etc? We are using MVC 5.0. 1: var routingValues = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current)).Values; var currentArea = (string) routingValues["area"] ?? string.Empty;

Implementing Routes for dynamic actions in MVC 4.0

丶灬走出姿态 提交于 2019-12-05 21:34:45
Is it possible to define a route in MVC that dynamically resolves the action based on part of the route? public class PersonalController { public ActionResult FriendGroup() { //code } public ActionResult RelativeGroup() { //code } public ActionResult GirlFriendGroup() { //code } } I want to implement a routing for my Group Action Method below Url: www.ParlaGroups.com/FriendGroup www.ParlaGroups.com/RelativeGroup www.ParlaGroups.com/GirlFriendGroup routes.MapRoute( "Friends", "/Personal/{Friend}Group", new { controller = "Personal", action = "{Friend}Group" } ); routes.MapRoute( "Friends", "

Make ASP.NET MVC Route Id parameter required

被刻印的时光 ゝ 提交于 2019-12-05 21:17:28
I have this route: routes.MapRoute( "PlaceDetails", "{controller}/{action}/{id}", new { controller = "Place", action = "Details", id = UrlParameter.Optional } ); This routes this fine: mysite.com/place/details/123 Making Id 123 available to the details action of the place controller - which can then lookup place '123'. However - this URL is also passed to the controller: mysite.com/place/details/ I want this to return HttpNotFound - but it sends a null Id to the controller - and requires me to handle that. It seems neater if the route itself achieves this rather than needing unseemly null

MVC 4 catch all route never reached

蹲街弑〆低调 提交于 2019-12-05 20:47:44
问题 When attempting to create a catch all route in MVC 4 (something I've found several examples of, and based my code on) it returns a 404 error. I'm running this on IIS 7.5. This seems like a straight forward solution, so what am I missing? One note, if I move the "CatchAll" route above the "Default" route it works. But of course then none of the other controllers are ever reached. Here is the code: Route.Config: routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new

asp.net mvc routing question

笑着哭i 提交于 2019-12-05 20:34:00
the default routing works fine mysite.com/home/about and i even see how to customize it to make it shorter so i can say: mysite.com/edit/1 instead of mysite.com/home/edit/1 but how can i make it longer to handle url like the following mysite.com/admin/user/1 // works mysite.com/admin/user/details // does not work mysite.com/admin/question/create // does not work i cant just treat the id as an action? i need a custom route? do i need to create new controllers for each table or can i route them all through the Admin controller thanks a lot As has been mentioned already, probably your best bet

MVC Custom Route. DataTokens[“Namespaces”] is ignored

南笙酒味 提交于 2019-12-05 19:43:48
I don't know why while creating a CustomRoute which inherits from Route , the field DataTokens["Namespaces"] is ignored. And I get the error: Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter. Here is the sample: Application_Start() public static void RegisterRoutes(RouteCollection routes) { //Create