asp.net-mvc-routing

Multiple optional parameters in MVC is not working

空扰寡人 提交于 2019-12-11 18:57:20
问题 My requirement is to provide optional parameters to urls. urls should be like the. http://test.com/118939 http://test.com/118939/test/2000/ I have written following routes public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); routes.MapRoute( "FAQDefault", "FAQ", new { controller = "FAQ", action = "Default" }); routes.MapRoute(null, "{id}", new { controller =

Web APi Routing Understanding

你离开我真会死。 提交于 2019-12-11 18:52:46
问题 I have created a new controller called WebPortalController but when I call it or try to call it via the browser I couldnt access the below method just said resource is not found. Do I need to add a new routing to the RoutesConfig.cs code if so how.? namespace WebApi.Controllers { public class WebPortalController : ApiController { // GET api/webportal private WebPortEnterpriseManagementDa _da = new WebPortEnterpriseManagementDa(); public ManagedType Get(string name) { ManagedType items = _da

MVC RedirectToAction is not working properly

孤者浪人 提交于 2019-12-11 17:45:19
问题 In one of my controllers, I do have a return that looks like this: return RedirectToAction("AdministerFiles/ViewDataFiles?catid=14"); but when it renders the result to the browser the string becomes this one: AdministerFiles/AdministerFiles/ViewDataFiles%3fcatid%3d14 how can I solve this ? thanks . 回答1: You just need the action as the parameter (along with the route data): return RedirectToAction("ViewDataFiles", new { catid = 14 }); If you want to specify the controller as well (it defaults

ASP.NET MVC Area not picking up the correct route

落爺英雄遲暮 提交于 2019-12-11 16:45:08
问题 I am in the process of debugging a routing issue on my MVC 3 application and I am using Phil Hacks routing debugger. I cannot seem to work out where the route highlighted in yellow below is originating. Each time I run my application with the following request http://www.mywebsite.com/auth/login?ReturnUrl=/ this route comes first and then gives me a 404 error as I do not have an index action. As you can see I have set my default routes to use the Login action method but still this route

ASP.NET MVC Routing, Need help creating route

走远了吗. 提交于 2019-12-11 16:04:42
问题 My current Routing rules are routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); routes.MapRoute( "Admin", // Route name "Admin/{controller}/{action}/{id}", // URL with parameters new { controller = "Admin", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); I have several

Classic ASP using MVC routing on IIS7

守給你的承諾、 提交于 2019-12-11 13:33:40
问题 After taking the first hurdle, I found something amusing. Direct access (i.e. /OLD/ASP/myFile.asp ) to the page works (well, no, but it returns a plausible ASP error ;) ). However, trying to route the page such as: routes.MapPageRoute( "OldASP", "Page/{*id}", "~/OLD/ASP/myFile.asp", false, new RouteValueDictionary(), new RouteValueDictionary(new { @id = @"\d+" }) ); Returns the magnificant There is no build provider registered for the extension '.asp'. error (which was originally solved for

ASP.NET MVC 5 routing, hide data in URL

亡梦爱人 提交于 2019-12-11 13:29:52
问题 I have two types of functionality for a action with a bool variable. [HttpGet] public ActionResult action(bool data = false) { if(data == false) { return View("view1"); } else { return View("view2"); } } It is a [httpGet] method. some link has data bool value as true and some has false . The url has the attribute like http://localhost:58241/action?data=False I want to hide the ?data=False or ?data=True from URL and should possess all the same functionality like before. I want the URL like

ASP.NET MVC 4 Override Controller Name

点点圈 提交于 2019-12-11 13:18:15
问题 Is it possible to override the controller name in ASP.NET MVC 4? It's needed for routing. There is [ActionName("some-action-name")] attribute to override the action name. Is it possible to do the same for a controller class name? It's needed to make a controller name in the routing to have dashes, like "some-controller-name" instead of "SomeControllerName" 回答1: Solved with routes. It's the only way to do it. Thanks for comments. 来源: https://stackoverflow.com/questions/15831869/asp-net-mvc-4

Routes for MVC 4 Web APIs?

心已入冬 提交于 2019-12-11 11:37:25
问题 In my initial stab at creating a MVC4 Web API. I've noticed a few things about the way routes are handled that seems a little off: Controllers no longer ever have more than 4 actions? A resource that only supports one HTTP verb still gets it's very own controller? The route hierarchy tends to be very flat, OR An extremely large number of routes must be specified/maintained compared to MVC apps for humans. I've created fairly large sites that use only two or three routes, but I'm just starting

Multilanguage menu for Mvc.sitemap with language in an Url

泄露秘密 提交于 2019-12-11 11:08:22
问题 My route: "{lang}/{controller}/{action}/{id}" {lang} here is: en-US, de-DE, etc Everything works right till moment I would like to switch language. When I switch language I am loosing part of the menu. my MenuHelperModel.chtml @model MvcSiteMapProvider.Web.Html.Models.MenuHelperModel @using System.Web.Mvc.Html @using MvcSiteMapProvider.Web.Html.Models <div class="hmenu"> <ul class="tabs"> @foreach (var node in Model.Nodes) { <li>@Html.DisplayFor(m => node)</li> } </ul> </div> @foreach (var