asp.net-mvc-routing

ASP.NET Web Api 2 - Attribute Based Routing - How do I force a parameter to query string only?

若如初见. 提交于 2019-12-13 04:34:17
问题 I am working on a Web Api 2 project and I am using attribute based routing. Here is a sample route: [Route("{id:int}", Name = "GetEmployeeById")] [HttpGet] public IHttpActionResult GetEmployee(int id) { ... } This works with the following URLs: ://host/employee/12345 ://host/employee?id=12345 What I would prefer is that the first form (the parameter in the URI), would not be allowed, and only the second form (query string) would work. What I've Tried Mostly, I've tried searching the web for a

MVC 3 Domain Routing

别说谁变了你拦得住时间么 提交于 2019-12-13 04:15:03
问题 I would like to know if the following is possible. I have a website called www.myweb.com. This website could be a directory of say football teams. The list of teams could be found here www.myweb.com/home/teamlist On selecting a team one would be take to www.myweb.com/teams/teama or www.myweb.com/teams/teamb etc the content under the teams area would be related to them e.g. www.myweb.com/teams/teama/fixtures www.myweb.com/teams/teama/news i have the above working but would like to know if it

ASP.NET Core MVC: How to change QueryString param into “pretty” URL param?

南楼画角 提交于 2019-12-13 03:50:00
问题 My issue is an aesthetic one. I have the following Controller: [HttpGet("[action]/{EmployeeTypeID:int?}")] public IActionResult FilterByType(int EmployeeTypeID = 1) { ... } Which is called when I go to the following routes, for example: /Employees/FilterByType /Employees/FilterByType/2 Great. The controller returns the following ViewModel to the View: public class EmployeesByTypeViewModel { public IEnumerable<Employee> FilteredEmployees { get; set; } public IEnumerable<SelectListItem>

Angular 2 and MVC routing

浪子不回头ぞ 提交于 2019-12-13 03:33:53
问题 I need some help as I cannot make Angular to call correctly an API inside Visual Studio 2017. Here is part of my code(I have imported and injected everything Angular needs as to work): @Injectable() export class GetCustomerInfoService { constructor(private http: HttpClient) { } getResults() { return this.http.get('http://localhost:65040/api/employees'); } } @Component({ selector: 'apply', templateUrl: './apply.component.html', providers: [GetCustomerInfoService] }) export class ApplyComponent

Wrong MVC route matched. Asp.net

牧云@^-^@ 提交于 2019-12-13 03:06:58
问题 This is my route registration code: routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "course_list", "course/list", new { controller = "course", action = "list" } ); routes.MapRoute( "course_view", "course/view/{id}", new { controller = "course", action = "list", id = UrlParameter.Optional } ); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); I have a link /course/view

Inconsistent MVC parameter error in IE

只谈情不闲聊 提交于 2019-12-13 02:34:42
问题 I've got a user who is seeing an error in my MVC3 application, that I can't explain. The exception is: System.ArgumentException: The parameters dictionary contains a null entry for parameter 'extractID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.PartialViewResult SelectExtract(Int32)' ... I understand what this exception usually means, but it shouldn't be happening here. The method is: [HttpPost] public PartialViewResult SelectExtract(int extractID) {...} The call comes

Why MVC keeps route values in URL without passing them directly

孤人 提交于 2019-12-13 02:26:41
问题 I have a question. Let's say I have this routes: /Guest/{var1}/{var2} /Guest/{var1}/{var2}/edit When I'm on the /Guest/123/321 page, I have a link to /Guest/123/321/edit?id=1 . There is a form on the page /Guest/123/321/edit?id=1 , which posts itself on the same address. Let's say that my Actions looks like: public ActionResult Index(int var1, int var2) { /* here is some a business logic */ return View(model); } [HttpGet] public ActionResult Edit(int id) { /* here is some a business logic */

ASP.Net MVC: Intercepting routing and forwarding to different actions/routes

微笑、不失礼 提交于 2019-12-13 01:15:09
问题 We have a REST API for our site. We've been versioning endpoints by prefixing the endpoint with the release version the endpoint was added or updated with. For example /v1/service-a /v2/service-b /v3/service-c The problem with this approach is we have our client code calling out to different versions of the endpoints. For example a page may call out to /v3/service-c and /v1/service-a. I'd like to set it up so that our developers can access the latest version of the API by just prefixing the

WebApiConfig.Register Clears routes defined by RouteConfig.RegisterRoutes apon deployment

淺唱寂寞╮ 提交于 2019-12-13 00:43:13
问题 I'm on struggle street here, When I try to add API controllers it seems to destroy all my MVC base routes and area routes. On my application start I call protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); Util.RazorDebuggingSetup(); BundleConfig.RegisterBundles(BundleTable.Bundles); } using System.Web.Mvc;

Asp.Net MVC Default Route

ぃ、小莉子 提交于 2019-12-12 20:22:25
问题 I have my default route defined like this routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); However if the user is logged in when they visit the site (This can happen if they ticked the remember me button last time the logged in) I want them to take a different default route and go straight to the logged in page. Is this possible in global.asax or will I need to put