attributerouting

Construct url in view for Web Api with attribute routing

回眸只為那壹抹淺笑 提交于 2019-11-28 03:21:49
问题 How can I get the url from web api in my view? Example (from the msdn-blog): [RoutePrefix("reviews")] public class ReviewsController : ApiController { // eg.: /reviews [Route] public IHttpActionResult Get() { ... } // eg.: /reviews/5 [Route("{reviewId}")] public IHttpActionResult Show(int reviewId) { ... } // eg.: /reviews/5/edit [Route("{reviewId}/edit")] public IHttpActionResult Edit(int reviewId) { ... } } Now I want to construct "/reviews/edit" in my view, how can I do this? I've tried

Route parameter with slash “/” in URL

霸气de小男生 提交于 2019-11-27 22:42:29
I know you can apply a wildcard in the route attribute to allow / such as date input for example: [Route("orders/{*orderdate}")] The problem with wildcard is only applicable to the last paramter in URI. How do I solve the issue if want to have the following URI: [Route("orders/{orderdate}/customers")] Update: I know there are few options to solve the issue by refactoring the code so please do not offer a solution something like: change the route template to [Route("orders/customers/{orderdate}")] change the date to a different format (e.g. "dd-mm-yyyy" ) ronnie @bet.. I think the

Query string not working while using attribute routing

依然范特西╮ 提交于 2019-11-27 06:29:11
I'm using System.Web.Http.RouteAttribute and System.Web.Http.RoutePrefixAttribute to enable cleaner URLs for my Web API 2 application. For most of my requests, I can use routing (eg. Controller/param1/param2 ) or I can use query strings (eg. Controller?param1=bob&param2=mary ). Unfortunately, with one of my Controllers (and only one), this fails. Here is my Controller: [RoutePrefix("1/Names")] public class NamesController : ApiController { [HttpGet] [Route("{name}/{sport}/{drink}")] public List<int> Get(string name, string sport, string drink) { // Code removed... } [HttpGet] [Route("{name}/

Multiple Controller Types with same Route prefix ASP.NET Web Api

点点圈 提交于 2019-11-27 04:05:57
Is it possible to separate GETs and POSTs into separate API Controller types and accessing them using the same Route Prefix? Here are my controllers: [RoutePrefix("api/Books")] public class BooksWriteController : EventStoreApiController { [Route("")] public void Post([FromBody] CommandWrapper commandWrapper){...} } [RoutePrefix("api/Books")] public class BooksReadController : MongoDbApiController { [Route("")] public Book[] Get() {...} [Route("{id:int}")] public Book Get(int id) {...} } Web API (1.x-2.x) does not support multiple attribute routes with the same path on different controllers.

MVC Attribute Routing Not Working

孤街醉人 提交于 2019-11-27 01:57:01
I'm relatively new to the MVC framework but I do have a functioning Web Project with an API controller that utilizes AttributeRouting (NuGet package) - however, I'm starting another project and it just does not want to follow the routes I put in place. Controller: public class BlazrController : ApiController { private readonly BlazrDBContext dbContext = null; private readonly IAuthProvider authProvider = null; public const String HEADER_APIKEY = "apikey"; public const String HEADER_USERNAME = "username"; private Boolean CheckSession() { IEnumerable<String> tmp = null; List<String> apiKey =

Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL

萝らか妹 提交于 2019-11-26 18:26:42
问题 ...guess I'm the first to ask about this one? Say you have the following routes, each declared on a different controller: [HttpGet, Route("sign-up/register", Order = 1)] [HttpGet, Route("sign-up/{ticket}", Order = 2)] ... you could do this in MVC 5.0 with the same code except for the Order parameter. But after upgrading to MVC 5.1, you get the exception message in the question title: Multiple controller types were found that match the URL. This can happen if attribute routes on multiple

Multiple Controller Types with same Route prefix ASP.NET Web Api

隐身守侯 提交于 2019-11-26 12:43:02
问题 Is it possible to separate GETs and POSTs into separate API Controller types and accessing them using the same Route Prefix? Here are my controllers: [RoutePrefix(\"api/Books\")] public class BooksWriteController : EventStoreApiController { [Route(\"\")] public void Post([FromBody] CommandWrapper commandWrapper){...} } [RoutePrefix(\"api/Books\")] public class BooksReadController : MongoDbApiController { [Route(\"\")] public Book[] Get() {...} [Route(\"{id:int}\")] public Book Get(int id) {..

Query string not working while using attribute routing

六眼飞鱼酱① 提交于 2019-11-26 10:24:56
问题 I\'m using System.Web.Http.RouteAttribute and System.Web.Http.RoutePrefixAttribute to enable cleaner URLs for my Web API 2 application. For most of my requests, I can use routing (eg. Controller/param1/param2 ) or I can use query strings (eg. Controller?param1=bob&param2=mary ). Unfortunately, with one of my Controllers (and only one), this fails. Here is my Controller: [RoutePrefix(\"1/Names\")] public class NamesController : ApiController { [HttpGet] [Route(\"{name}/{sport}/{drink}\")]