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
0
votes
1 answer

Using attribute routing on a controller is forcing me to manage all routes

I am just getting to grips with Asp.net Core and I'm trying to set up a basic site. I want to build an admin panel that is under a subdirectory. I have a simple controller which was scaffolded by the EF crud feature. So it seems that from the…
rtpHarry
  • 13,019
  • 4
  • 43
  • 64
0
votes
1 answer

Attribute routing - show logged in user id in the url

I am using MVC custom authentication in my project and I am clueless about how do I decorate my URL as per my requirement. Basically what I need is, whenever the user is authenticated and gains access to my application he is redirected to the main…
Janet
  • 21
  • 1
  • 5
0
votes
0 answers

ASP.Net MVC attribute-routed HTTP POST action not getting correct parameter

I have following controller with attribute routing. While making AJAX request with some parameter to "FileActionDefault" action, I have get routing attribute instead of AJAX action request…
BALA MURUGAN
  • 1,825
  • 3
  • 16
  • 17
0
votes
1 answer

Asp.Net Mvc Multiple Attribute Routing

I have a controller (CarsController). I want to set multiple route to action in this controller. For example; public class CarsController : Controller { [Route("cars/create")] [Route("cars/edit/{id}")] public action CreateOrEdit(int?…
0
votes
0 answers

Heisenbug - Attribute routing occasionally fails on a POST

Occasionally when hitting a POST action method I'll get this exception: Error Message: (System.Web.HttpException): No matching action was found on controller 'xyz'. This can happen when a controller uses RouteAttribute for routing, but no action on…
nmit026
  • 3,024
  • 2
  • 27
  • 53
0
votes
1 answer

Unable to POST to Web API endpoint using attribute routing

I have a Web API project that uses a default route of "api/{controller}/{id}" where "id" is optional. In most cases this is sufficient but in some cases I need attribute routing. In this specific case, I have…
DesertFoxAZ
  • 439
  • 1
  • 4
  • 14
0
votes
0 answers

Attribute routing based on the existence of a querystring parameter

I would like two different methods to be called depending on whether the request is GET /things/123 or GET /things/123?preview Obviously, this would be a workaround: [RoputePrefix("api/things")] ... [HttpGet, Route("{id}")] public object…
Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154
0
votes
0 answers

BeginForm and AttributeRouting

I am having trouble figuring out or understanding how to make my routing work as i would like it to work in my project. I have the following form in a view @using (Html.BeginForm("Filter", "Aanbod", FormMethod.Get)) {
0
votes
1 answer

Default route interferes with defined path in attribute routing in ASP.MVC

I have a controller with an action method and I have configured attribute routing: [RoutePrefix("foos")] public class FooController : BaseController { [HttpGet] [Route("")] public ActionResult List() { …
Arkadiusz Kałkus
  • 17,101
  • 19
  • 69
  • 108
0
votes
0 answers

Unable to get multiple literal routings to work in the same controller - Web Api 2

I'm using attribute routing and am having this controller with two Get-methods. When requesting any of these two Get methods I get 404 back and I don't understand why since I've followed this guide from Microsoft (especially this part). This is how…
Andreas
  • 2,336
  • 2
  • 28
  • 45
0
votes
2 answers

MVC Custom action route - 404 error

I want to use custom URL route: http://localhost/MyController/MyView/11/25?someID=0 to do so, I have the following action: [Route("{page}/{size}")] public ActionResult MyView(int page = 0, int size = 25, FilterModel filterModel = null) { …
Tony
  • 12,405
  • 36
  • 126
  • 226
0
votes
0 answers

Asp.net Web API Attribute Routing does not work with "."

Attribute Routing with a "." is not working in my Web API project Sample URL which does not work http://localhost:8082/image/TestImage.jpg [RoutePrefix("image")] public class TestController : ApiController { …
Rwiti
  • 1,056
  • 1
  • 13
  • 31
0
votes
2 answers

Default attributing routing not working

I am working on a new project and i have decided to use attribute routing alone. This is my RouteConfig file: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); …
Willie
  • 239
  • 3
  • 15
0
votes
1 answer

How do you set the default route in MVC6 when using attributes?

In MVC5 you could set the default route using the following attribute on a controller? [Route("{action=index}")] What is the equivalent of this in MVC6? Update This is the code I had in MVC5 [Route("{action=index}")] public class…
0
votes
1 answer

Converting API from REST-like routing to named parameters

I have created an API that looks for parameters as such ... http://server/api/contollerName/param1/param2/param3 for this pattern I used the following method attribute: [Route("api/myController/{param1}/{param2}/{param3}")] [HttpGet] public…
webworm
  • 10,587
  • 33
  • 120
  • 217