asp.net-mvc-routing

how to remove the controller name from the url using rout in MVC [duplicate]

夙愿已清 提交于 2019-11-29 13:08:38
This question already has an answer here: ASP.NET MVC - Removing controller name from URL 5 answers How to remove the controller name from the URL in MVC 5. I tried to add the route in the route.config public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapMvcAttributeRoutes(); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); routes.MapRoute( name: "Special", url: "action/{id}", defaults: new {

Link to a root controller from area controller in ASP MVC

混江龙づ霸主 提交于 2019-11-29 11:58:11
问题 How can I link to one of my root controllers from one of my areas? <% Html.RenderAction("Action", "Page", new {area = "root", name = "Admin"}); %> This gives me an error: No route in the route table matches the supplied values. I have a controller named Page in a folder named Admin in my root controller collection. I can reach this controller by typing \Admin\Page. This is how I registered the route: routes.MapRoute( "Admin", "Admin/{controller}/{action}/{id}", new { controller = "Admin",

Considerations when turning on RouteExistingFiles

♀尐吖头ヾ 提交于 2019-11-29 11:37:24
I am looking to generate some CSS files dynamically in my Content folder. At the moment, this folder has an ignore route ( routes.IgnoreRoute("Content/{*wildcard}"); ) and, I'd like that to remain, as I don't need/want most of my content folders to go into the MVC request lifecycle. Example: routes.MapRoute( "DynamicCSS", "Content/Css/Dynamic/{guid}.css", new { controller = "Site", action = "GenerateCSS" }, new { guid = @"^([0-9a-fA-F]){8}([0-9a-fA-F]){4}([0-9a-fA-F]){4}([0-9a-fA-F]){4}([0-9a-fA-F]){12}$" } ); //If the file has already been generated, IIS should just return the file, saving a

ASP.NET MVC - get list of objects from query string

馋奶兔 提交于 2019-11-29 11:07:30
I'm passed a list of parameters. Such as "Name", "Id", "Type". There will be an many of these in url, like so: "Name=blah1,Id=231,Type=blah1;Name=blah2,Id=2221,Type=blah1;Name=blah3,Id=45411,Type=blah3;" I wonder if there is a way to map these query parameters to a List of objects. So, I can create an object: MyTestObject {Name;Id;Type} and can say in my controller Index(IList<MyTestObject> params) params will be filled in with data from query string. Something that is similar to http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx Kuncevič Yes, ASP.NET MVC could automatically

Can anyone recreate the following bug I'm experiencing in routes with 2 or more optional parameters, in .NET 4.0 / MVC3?

爱⌒轻易说出口 提交于 2019-11-29 10:58:41
I know that if you think you found a bug in the .NET framework you are most likely wrong, but that's why I'm writing this question, so please hear me out. I am fairly certain that there is a difference between the routes in .NET 3.5 and .NET 4.0 when it comes to optional parameters. Specifically if you have more than one optional parameter in your route. I have not been able to find this breaking change noted in any release notes of either .NET 4.0 or MVC 3 so thats why I call it a bug. EDIT: This bug only manifests itself when you try to build a route url using code like the url or html

MVC MapPageRoute and ActionLink

主宰稳场 提交于 2019-11-29 09:57:47
I have created a page route so I can integrate my MVC application with a few WebForms pages that exist in my project: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // register the report routes routes.MapPageRoute("ReportTest", "reports/test", "~/WebForms/Test.aspx" ); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } This has created a problem whenever I use Html.ActionLink in my Views: <%: Html.ActionLink(

Dynamic routing action name in ASP.NET MVC

爷,独闯天下 提交于 2019-11-29 08:55:21
I would like to create a dynamic routing to a URL like following: http://localhost:51577/Item/AnyActionName/Id Please note that the controller name is static and doesn't need to be dynamic. On the other hand, I need to have the action name part dynamic so that whatever is written in that part of URL, I would redirect the user to the Index action inside of Item controller. What I have tried so far is: public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( "Items", "Item/{action}/{id}", new { controller = "Item", action = "Index", id = UrlParameter.Optional }); } And when I

Dot character in ASP.NET MVC 3 route parameters

折月煮酒 提交于 2019-11-29 08:33:59
I have no custom routes in my application, only the default one. If i try to open localhost/myapp/controller/action/bla.bla it works fine on my machine (Windows 7 x32, both Cassini and IIS) but fails on the server (2008 R2 x64). Found similar question but the solution doesn't work. Also, found this article where Eilon says it's a special character for MVC and it's "by design". Why there is difference between my machine and the production box and how do i fix it? Update : the problem site has ExtensionlessUrl-ISAPI-4.0_64bit and ExtensionlessUrl-Integrated-4.0 enabled and mapped to "*.". There

AngularJs routing with Asp.Net Mvc

自闭症网瘾萝莉.ら 提交于 2019-11-29 07:45:57
I'm trying to build a SPA with Asp.Net MVC. for this I'm using angularJs routing . This is my project hierarchy. My Layout.cshtl code <html lang="en" ng-app="ProjectTrackingModule"> <head> <script src="~/Scripts/jquery-2.1.0.min.js"></script> <script src="~/Scripts/angular.min.js"></script> <script src="~/Scripts/angular-route.min.js"></script> <script src="~/Scripts/app.js"></script> </head> <body> <a href="#Home">Home</a> <a href="#Projects">Projects</a> <div ng‐view style="margin‐left: 10%; margin‐right: 10%;"> </div> //... footer </body> </html> My app.Js code is as follow: var app =

angularjs with cshtml page only not html pages with web api 2

我们两清 提交于 2019-11-29 07:38:12
I'm having asp. net mvc4 project. Angularjs is integrated. I have already built HTML pages and WEB APIs 2 as per previous requirements. Now for some reason i have to go with CSHTML pages. previously I had only web api project template so i couldnt go with cshtml pages as ONLY MVC controller can return partial page(cshtml) but i was using only web apis... So changed whole project template and so now i can have mvc controllers... ... In short, currently I have mvc4 project with already built web apis and html pages..... I just want to use CSHTML pages instead of using HTML pages rest things