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
6
votes
2 answers

Why is my attribute routing not working?

This is what my controller looks like: [Route("api/[controller]")] [Produces("application/json")] public class ClientsController : Controller { private readonly IDataService _clients; public ClientsController(IDataService dataService) …
ProfK
  • 49,207
  • 121
  • 399
  • 775
6
votes
1 answer

Is Attribute Routing possible in Azure Functions

I am trying to enforce a route parameter to be guid but getting below error "Exception while executing function: GetUser -> One or more errors occurred. -> Exception binding parameter 'req' -> Invalid cast from 'System.String' to…
Venkata Dorisala
  • 4,783
  • 7
  • 49
  • 90
6
votes
2 answers

Multiple optional parameters web api attribute routing

I am new to attribute routing, and I am not sure if this is even possible. I have an attribute route, which works fine like this: [HttpGet] [Route("GetIssuesByFlag/{flag:int=3}")] public IEnumerable GetIssuesByFlag(int flag) Now I want to…
Harry
  • 3,333
  • 3
  • 18
  • 28
6
votes
2 answers

Route Prefix VS Controller Name ( Web api )

I was wondering that if we use RoutePrefix attribute in our web api controller with a different name from controller's actual name. So would it work or not? As far as i did [RouterPrefix("quotation")] public class SaleOrderController :…
6
votes
2 answers

Url.Action generates query instead of parameter URL

This is the controller class. I am showing only method signatures. [Authorize] [RoutePrefix("specification")] [Route("{action=index}")] public class SpecificationController : BaseController { [HttpGet] …
Robert
  • 2,407
  • 1
  • 24
  • 35
6
votes
1 answer

How to map query parameters with dashes in their names

Is there a way to map the query string parameter my-param to the controller method parameter myParam in Web API 2 (preferably using attribute routing)? This means a URI like... library.com/books?search-text=REST ...should be routed to the…
Good Night Nerd Pride
  • 8,245
  • 4
  • 49
  • 65
6
votes
2 answers

ASP.NET MVC 5 Attribute Routing: Url.Action returns null

I am experiencing an issue with a refactoring of our payment processing action method (called by our 3rd-party online payment provider). We have a product controller with the [Authorize] and [RoutePrefix("products")] attributes at the class level,…
d_mcg
  • 788
  • 2
  • 11
  • 19
6
votes
1 answer

Is it possible to select an Action with AttributeRouting in .NET MVC based on the Media Type of the Accept header?

I want to select an Action of my Controller based on the Media Type requested in the Accept header. For example, I have a resource called a subject. Its assigned route is: GET /subjects/{subjectId:int} Normally, the browser is requesting…
crush
  • 16,713
  • 9
  • 59
  • 100
6
votes
1 answer

Is it possible to use attribute routing and convention based routing in the same controller?

I have a controller called HotelsController to insert and edit hotels. It has the following setup (method implementation removed for simplicity): [RoutePrefix("{member_id:int}/hotels")] public class HotelsController : ApplicationController { …
6
votes
1 answer

Use custom route handler with MVC5 attribute routing

Using the library AttributeRouting, I was able to configure attribute routing to use a custom route handler (inheriting MvcRouteHandler): routes.MapAttributeRoutes(cfg => { cfg.UseRouteHandler(() => new MultiCultureMvcRouteHandler()); …
6
votes
1 answer

MVC5 : Attribute Routing Precedence Among Controllers

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 :…
Yorro
  • 11,445
  • 4
  • 37
  • 47
6
votes
1 answer

MVC Attribute Routing - Default Controller Index with GET and POST

We have an MVC 5.1 project and are using attribute routing. Everything is working fine except the default page which has a login form on it. [RoutePrefix("Home")] public class HomeController : BaseController { [Route("~/")] [Route] …
6
votes
1 answer

Attribute Routing for Multiple DateTime parameters

I have defined attribute route which takes two parameter as datetime [Route("{controller}/{action}/{*startDate:datetime}/{*endDate:datetime}")] public bool OverView(DateTime startDate,DateTime endDate) { var dt =…
Ammar Khan
  • 346
  • 1
  • 9
  • 27
6
votes
1 answer

Requested resource does not support http method "PUT"

I'm using AttributeRouting with my Web API (MVC 4). Why does this work? [AcceptVerbs("PUT")] [PUT("api/v1/tokens/current")] public MemoryToken UpdateToken([FromBody] DeviceTokenViewModel viewModel) {...} And this one does not? …
Ingmar
  • 1,525
  • 6
  • 34
  • 51
5
votes
1 answer

Trying to create a default ASP.NET MVC Route with AttributeRouting

i've just started using AttributeRouting with my ASP.NET MVC3 application. I started out with -no- controllers at all. (New Empty MVC3 Application) I then made an area. (called: Documentation) I then added a controller (called:…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647