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

generate url with Url.Action helper from attribute routing controller with prefix

i have definned a Map route like this: app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=User}/{action=Student}/{id?}"); }); and i have an…
MorgoZ
  • 2,012
  • 5
  • 27
  • 54
0
votes
3 answers

Mvc attribute routing issue with multiple parameters

I have defined Details method in Pro controller and i want to map this method to multiple types of url. Please check below code, i have tried on another method with one parameter and it is working but in this case it's not working with multiple…
0
votes
1 answer

Attribute routing for two actions leads to a "Not valid OData path template"

So i have two functions that return a customer, which get feeded by two different parameters. One being the ID of the customer and the other being his customer number. My controller: using System.Linq; using System.Net; using System.Web.Http; using…
Peter
  • 135
  • 2
  • 13
0
votes
0 answers

How can we skip the optional null parameters when using pagination via attribute routing in MVC C#?

I am using attribute routing in MVC 5 application on a controller which is used to fetch list and performs searching sorting and pagination : [HttpGet] [Route("Admin/UserList/{searchBy?}/{search?}/{page?}/{sortBy?}")] public…
0
votes
1 answer

Attribute Routing not existing routes

I have a project with Attribute routing like: [Route("home")] public class HomeController : Controller { [HttpPost] public IActionResult Post(int id) { } [HttpGet] public IActionResult Get() { } } Now I want…
wydy
  • 173
  • 14
0
votes
0 answers

ASP.NET MVC - Multiple controller types were found that match the URL

Using ASP.NET MVC 5.2 with attribute routing. I have 2 actions in separate controllers: public class AccountController { [Route("login")] public ActionResult Login() { } } public class HomeController { [Route("{category}")] public…
dima
  • 1,181
  • 1
  • 9
  • 20
0
votes
0 answers

MVC Child Only Action causes stackoverflow with attribute routing

I have a route define for controller using attribute routing [RoutePrefix("blog")] public class BlogController : Controller { [HttpGet] [Route("detail")] public ActionResult Detail() { return Content("hello"); } } I have a…
Ammar Khan
  • 346
  • 1
  • 9
  • 27
0
votes
1 answer

Unable to hit any attributed routes in new WebApi project - only 404s returned

I'm building a new Web API project from scratch and am unable to get any response other than 404 (Not Found). The routes for each controller and method are declared in attributes. Here is my Global.asax Application_Start method. protected void…
awj
  • 7,482
  • 10
  • 66
  • 120
0
votes
1 answer

Web API 2 Post 404s, but Get works

I'm confused... I have a very simple Web API and controller, which works fine if I have a GET request, but 404's if I have a POST request. [RoutePrefix("api/telemetry/trial")] public class LoginTelemetryController : ApiController { …
jleach
  • 7,410
  • 3
  • 33
  • 60
0
votes
2 answers

How to correctly use optional route parameters in this controller to simplify it?

I have a controller that is made with ASP.NET and I really want to simplify that thing with quick view: // REST representation of Storage // There is always at least two options to view them // Data as is or Quick view at metrics…
Roman
  • 733
  • 1
  • 5
  • 14
0
votes
1 answer

ASP .NET MVC 5.2 Inherited Route: Multiple controller types were found that match the URL

I'm trying to use a base controller with the [InheritedRoute] attribute. The base class and controllers are created like this: [InheritedRoute("app/{controller}/{action=index}/{id?}")] public abstract class MyBaseController : Controller { …
0
votes
0 answers

Customize URL with Attribute Routing

With conventional routing, you can customize the URL that is generated by an Anchor Tag Helper by implementing IRouter.GetVirtualPath. GetVirtualPath isn't called when using attribute routing, however. Is there an equivalent way to customize the URL…
Edward Brey
  • 40,302
  • 20
  • 199
  • 253
0
votes
1 answer

How to use Route Constraint and Attribute Routing together?

I use Route Constraint in my website and Now I need to use Attribute Routing. Route Constraint class: public class BusConstraint : IRouteConstraint { private RouteDB routeDb = new RouteDB(); public bool Match(HttpContextBase…
hmahdavi
  • 2,250
  • 3
  • 38
  • 90
0
votes
0 answers

URL generation with attribute routing

I have three overloaded actions with similar routes; Routing is working fine, the problem is with link generation. The code is similar to this: [RoutePrefix("Prefix")] public partial class MyController : Controller { [ActionName("Index"),…
0
votes
0 answers

How to distinguish between a query string variable and a URL segment variable with Web API 2.0 attribute routing?

Lets say I have the following ApiController and method: [RoutePrefix("configs")] public class FullConfigController : ApiController { [Route("{ID}")] [HttpGet] public string GetConfig(Guid ID) { return "my config data"; …
Ultratrunks
  • 2,464
  • 5
  • 28
  • 48