Questions tagged [attributerouting]

Define your routes using attributes on action methods in ASP.NET MVC and Web API.

NOTE: Attribute Routing support is currently built into Web API. You can read more information about it here: http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2

371 questions
4
votes
2 answers

Asp.Net WebAPI and AttributeRouting - no overloaded attribute constructor?

I have just downloaded AttributeRouting NuGet package for WebAPI and having a problem within my controller. I thought the way to use it was to have something like: public class InboxController : ApiController { private IInboxService…
jaffa
  • 26,770
  • 50
  • 178
  • 289
4
votes
3 answers

Get route name from inside view?

Using Attribute Routing you can define a route name. Is there a way I can get the name of the used route from inside my view?
mpen
  • 272,448
  • 266
  • 850
  • 1,236
4
votes
2 answers

How to test an MVC route with optional querystring parameters

I have this controller method: [GET("/whatever/list")] public ActionResult Index(string sortby, string order) I'm trying to test it with MvcContrib route testing: "~/whatever/list".ShouldMapTo(c => c.Index(string.Empty,…
T. Stone
  • 19,209
  • 15
  • 69
  • 97
4
votes
1 answer

Hide Area in URL using AttributeRouting

We are using Areas to version an API written in ASP.NET MVC3 with AttributeRouting to define our routes. Right now we have a "v1" area that is our first version of API. When we got to v2, we will copy over v1 and make modifications. I want to use…
3
votes
2 answers

MVC Conventional and Attribute routing not working together

I am using conventional routing on an ASP.Net MVC project and would like to enable Attribute routing in parallel. I have created the following but I am getting a 404 on the conventional route when enabling attribute routing public static void…
Adrian
  • 670
  • 10
  • 24
3
votes
1 answer

RouteAttribute's Order is completely ignored on IRouteConstraint

We have an IRouteConstraint that is getting checked much more than it should. Upon further testing, it looks like that Order on [Route] gets ignored by route constraints. For example, if I have the following constraint: public class TestConstraint :…
Jerad Rose
  • 15,235
  • 18
  • 82
  • 153
3
votes
1 answer

Attribute Routing with Parameters in Asp.Net Web API 2

In Asp.Net Web API 2 Attribute routing, If i call any attribute i need to get all list of data mapping with that attribute but I am getting the first element of a sequence that satisfies a condition. My controller looks like…
3
votes
1 answer

Attribute routing recognize optional query string parameters

I have a API action: [HttpGet, Route("{id}/overview/")] public async Task Overview(string id, DateTime from, DateTime? to) { ... } As you noticed, to is optional parameters, but when I make…
user348173
  • 8,818
  • 18
  • 66
  • 102
3
votes
1 answer

Attribute vs Conventional Routing

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…
3
votes
1 answer

Is it possible to only accept specific value of a route parameter using route attribute?

The following code does what I want to do. If the string parameter ForSaleOrRent has any value but ForSale or ForRent the action method returns HttpNotFoundResult. My question is this doable using only Route…
3
votes
1 answer

Passing Complex Objects to ASP.NET Web API Using FromUri

I want to bind the URL parameters to my Point object using attribute routing and the [FromUri] attribute such that the following URL is possible: /foo-1,2 public IHttpActionResult PostFoo( [FromBody] string content, [FromUri] Point…
Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
3
votes
1 answer

AttributeRouting conflicting parameter route with string route

I have two controllers, ItemsController and SingleItemController which both inherit from ApiController. Both have RoutePrefix items/inventory defined on the controllers, like so: [RoutePrefix("items/inventory")] I'm using AttributeRouting in Web…
Gaui
  • 8,723
  • 16
  • 64
  • 91
3
votes
1 answer

Mvc6 routing (RoutePrefix and AreaPrefix)

I've starting look to move applications on to MVC6 to take advantage of the new framework. One of the biggest problems I've run in to is the routing (Attribute routing only, I have completed removed the default routes). My applications are…
eddpoints
  • 183
  • 3
  • 8
3
votes
2 answers

MVC Routing optional string parameter and ugly urls

I am using mvc 5.2.3 on 4.5.1 and want these urls /Nike/Shoes /Nike/Shoes/Running /Nike/Shirts/2002342345 /Nike/Shoes/Running/98765432234 My controller has: [HttpGet] [Route("{brand}/{category}/{subcategory}/{page:int?}",…
JP Hellemons
  • 5,977
  • 11
  • 63
  • 128
3
votes
1 answer

MVC 5 how to specify constraints using attribute routing

I'm trying to do full attribute routing, without conventional routing, and trying to tell my routes which area they belong to based on the current domain. In convention routing, I can specify my object constraints with this as an…
Ian Davis
  • 19,091
  • 30
  • 85
  • 133