Questions tagged [asp.net-mvc-routing]

Questions about routing within ASP.NET (including MVC).

The ASP.NET Routing module is responsible for mapping incoming browser requests to particular ASP.NET handlers. It is commonly used to map ASP.NET MVC controller actions, but routing is also used with ASP.NET Web Forms, ASP.NET Web API, route attribute (Web API2) and custom handlers.

Learn more about ASP.NET Routing on MSDN

4131 questions
59
votes
2 answers

ASP.NET MVC 5 culture in route and url

I've translated my mvc website, which is working great. If I select another language (Dutch or English) the content gets translated. This works because I set the culture in the session. Now I want to show the selected culture(=culture) in the…
juFo
  • 17,849
  • 10
  • 105
  • 142
59
votes
17 answers

The view 'Index' or its master was not found.

The view 'Index' or its master was not found. The following locations were searched: ~/Views/ControllerName/Index.aspx ~/Views/ControllerName/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx I got this error when using ASP.Net mvc…
Fitzchak Yitzchaki
  • 9,095
  • 12
  • 56
  • 96
59
votes
3 answers

ApiController returns 404 when ID contains period

I have an ApiController and I want to use email addresses as the ID parameter for requests: // GET api/employees/email@address.com public CompactEmployee Get(string id) { var email = id; return GetEmployeeByEmail(email); } However, I cannot…
Jon
  • 4,925
  • 3
  • 28
  • 38
58
votes
16 answers

No type was found that matches the controller named 'User'

I'm trying to navigate to a page which its URL is in the following format: localhost:xxxxx/User/{id}/VerifyEmail?secretKey=xxxxxxxxxxxxxxx I've added a new route in the RouteConfig.cs file and so my RouteConfig.cs looks like this: public class…
57
votes
5 answers

How to get current controller and action from inside Child action?

I have a portion of my view that is rendered via RenderAction calling a child action. How can I get the Parent controller and Action from inside this Child Action. When I use.. @ViewContext.RouteData.Values["action"] I get back the name of the…
JBeckton
  • 7,095
  • 13
  • 51
  • 71
48
votes
2 answers

Attribute Routing not working in areas

Scenario: I have a Forms area in my ASP.NET MVC 5 site. I'm trying to redirect to the Details Action which uses a custom route defined using the new Attribute Routing feature. The RedirectToAction: return RedirectToAction("Details", new { slug…
Thomas Stock
  • 10,927
  • 14
  • 62
  • 79
46
votes
4 answers

How to correctly use Html.ActionLink with ASP.NET MVC 4 Areas

I recently discovered Areas in ASP.NET MVC 4, which I have successfully implemented, but I'm running into troubles with the @Html.ActionLink helper in my Razor views. The URL this helper generates always seems to be relative to the URL of the…
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
44
votes
15 answers

ASP.NET CORE, Web API: No route matches the supplied values

PLEASE NOTE: This question was asked in 2016. The original answer to this problem was to update the microsoft api versiong package. In the current days, the problem reoccurs, but for other reasons. Original Question: i have some problems with the…
42
votes
5 answers

Infinite URL Parameters for ASP.NET MVC Route

I need an implementation where I can get infinite parameters on my ASP.NET Controller. It will be better if I give you an example : Let's assume that I will have following urls :…
tugberk
  • 57,477
  • 67
  • 243
  • 335
42
votes
3 answers

How am I supposed to use ReturnUrl = ViewBag.ReturnUrl in MVC 4

I'm working on 'ASP.NET MVC 4' application. I'm using/learning SimpleMembershipProvider and try to stick to the default logic created by VS2012 with the Internet template (if I'm not mistaken, the one with 'SimpleMembershipProvider' out of the box).…
Leron
  • 9,546
  • 35
  • 156
  • 257
41
votes
3 answers

How to access the current HttpRequestMessage object globally?

I have a method which creates an HttpResponseMessage containing an Error object which will be returned based on the current request media type formatter. Currently, I have hardcoded the XmlMediaTypeFormatter but I'd like to be able to find the…
The Light
  • 26,341
  • 62
  • 176
  • 258
40
votes
6 answers

How can I create a route constraint of type System.Guid?

Can anyone point me in the right direction on how to map a route which requires two guids? ie. http://blah.com/somecontroller/someaction/{firstGuid}/{secondGuid} where both firstGuid and secondGuid are not optional and must be of type system.Guid?
devlife
  • 15,275
  • 27
  • 77
  • 131
39
votes
1 answer

ASP.NET MVC Areas with shared layout

I have defined an area (Admin) in my ASP.NET MVC 3 application, created _ViewStart.cshtml in that area and addedLayout = "~/Views/Shared/_Layout.cshtml"; to it to have a unified site layout. I also added the following code to _Layout.cshtml: if…
Kamyar
  • 18,639
  • 9
  • 97
  • 171
39
votes
3 answers

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

How do I generate friendly URLs within the ASP.NET MVC Framework? For example, we've got a URL that looks like this: http://site/catalogue/BrowseByStyleLevel/1 The 1 is Id of the study level (Higher in this case) to browse, but I'l like to reformat…
Kieron
  • 26,748
  • 16
  • 78
  • 122
39
votes
1 answer

How can I redirect my action to the root of the web site?

I have the following code in my controller to redirect my user after he has logged out: public ActionResult Logout() { FormsAuthentication.SignOut(); return new RedirectToRouteResult( new…
user1321237