asp.net-mvc-routing

ASP.NET MVC 3.0 Routing behaviour

蓝咒 提交于 2019-12-24 19:28:24
问题 I have controller BlogController with a couple of actions: 1)Index(string id) - show all posts/show single post if parameter id specified 2)New() - add new post 3)Delete() - delete post 4)And some more another actions So if i type in browser mysite/blog i could see all posts if i type mysite/blog/postnameid i want to see single post. the problem is when i type mysite/blog/postnameid it is not working ( The resource cannot be found. ), but if i type mysite/blog/index/postnameid this way it is

MVC 2.0 - different view based on URL with shared controls

烂漫一生 提交于 2019-12-24 18:43:23
问题 I have 2 master pages. One is intended to be shown in a normal standalone website. The other is to be used in external sites as an Iframe. I want to be able to show the normal page at http://example.com/home/index and the iframed version at http://example.com/framed/home/index I want to have controls that will postback to one controller so I don't have to duplicate logic, so they must be available in both the normal and iframed versions. My problem is that when I try and use areas, I just can

MVC3 map routes to static file structure

醉酒当歌 提交于 2019-12-24 18:05:13
问题 Let's say I have an MVC application that routes requests according to the standard /{controller}/{action} pattern. I also want to be able return static files from a nested directory structure. For example, I want the root URL: /MyApplication/Static/folder/subfolder/somefile.xml to return the file at the physical location ~/Static/folder/subfolder/somefile.xml, and so on. Is this what the "MapPageRoute" method is for? If so, is it possible to do something like this? routes.MapPageRoute("static

MVC Ajax action relative to current controller

北战南征 提交于 2019-12-24 15:33:09
问题 I'm trying to get an Ajax call from a link in a master page. So I want to specify only the action relative to the current page/controller. i.e. $.ajax({ url: '/Save', type: "GET", // .. etc }); I want to call the "Save" action of whatever controller served the page. I thought this would work straight off, but it doesn't appear to. Is there an elegant solution? 回答1: If you got this straight into your view, you could do $.ajax({ url: '@Url.Action("Save")', type: "GET", // .. etc }); If not, and

MVC 3 Duplicated Controller names in AJAX post

自闭症网瘾萝莉.ら 提交于 2019-12-24 15:15:59
问题 If from the page localhost:nnnn/Class I click on an AJAX link that will post to 'Class/AddClass' I get a RawUrl of Class/AddClass and it works just fine. If from the page localhost:nnnn/Class/Index I click the same link I get a RawUrl of Class/Class/AddClass and it (obviously) doesn't work. I realize I'm in Routing Hell, but who's rewriting the URL and why? I painstakingly stepped through the jQuery code and indeed it's posting to Class/AddClass. Thanks for insight... Eric 回答1: It is not

asp.net core web api center routing

流过昼夜 提交于 2019-12-24 07:39:06
问题 I have an issue related with asp.net core center routing . I know we could use Attribute Routing, but I did not find anything related with center routing like asp.net web api. Something like below: routes.MapHttpRoute( name: "API Default", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); Could you share me how to achieve above function in asp.net core? If there is no built-in function, could custom routing service achieve this? Regards, Edward 回答1:

ASP.NET MVC IgnoreRoute method doesn't work correctly when URL starts with “/Views/”

依然范特西╮ 提交于 2019-12-24 07:09:21
问题 I use ASP.NET MVC in my application. Users can specify their own images, styles, scripts by including them on the page. But when they specify URL to the file which not exists then routing mechanism tries to find controller and action by URL to image or styles etc. I've added a method IgnoreRoute and specified there all extensions I don't want to handle by routing. It works correctly until URL doesn't starts with "Views/...". In this case URL passes into application and executes error 404

Handling ASP.NET MVC Routing in External JavaScript

扶醉桌前 提交于 2019-12-24 06:04:58
问题 What's the best way to avoid hardcoding URL's in JavaScript (primarily used when making AJAX calls)? In the past: Render JavaScript variable with result of @Url.Action or @Url.RouteUrl Pass result of @Url.Action or @Url.RouteUrl to JavaScript in init/ctor. Is there a better way? It would be good to do something like this: var url = $.routes("actionName", "controllerName") // or "routeName" for named routes $.post(url, { id = 1 }, function() { //.. }); Which of course isn't really possible

correct me on url routing in mvc

时光毁灭记忆、已成空白 提交于 2019-12-24 05:32:32
问题 In my globas.asax file i have one register route routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Authentication", action = "BigClientLogin", id = UrlParameter.Optional } // Parameter defaults ); and in my action "BigClientLogin" it redirects to a new action called "NewLogin" . So at present my current url looks like "http://localhost:65423/Authentication/NewLogin" .But i need my url in "http://localhost:65423/Login" format. To

MVC Routing for categories with spaces

ε祈祈猫儿з 提交于 2019-12-24 03:50:53
问题 I have a website that has categories for the products. I wanted to have the categories defined in a route pretty much like www.domain.com/categoryA. Here's my problem what if I have category in my database that is 'Boxing Gloves' how do I handle the space in the category name? 回答1: You can have spaces encoded as %20, but that doesn't really make for pretty urls. I'd suggest you convert them to dashes and disallow dashes in category names. You could also disable spaces and force users to use