asp.net-mvc-routing

URL.Action includes id when constructing URL

牧云@^-^@ 提交于 2019-11-27 14:41:53
问题 I'm using ASP.Net MVC. Here's my code snippets from a controller named Course: public ActionResult List(int id) { var viewmodel.ShowUrl = Url.Action("Show", "Course"); ... } public ActionResult Show(int id) { ... } viewmodel.ShowUrl picks up whatever the value is of the "id" parameter. So viewmodel.ShowUrl becomes "/Course/Show/151" (value of id is 151); I want to be able to set the id part on the client based on user interaction. I want the value of viewmodel.ShowUrl to be "/Course/Show".

MVC 2 AreaRegistration Routes Order

萝らか妹 提交于 2019-11-27 13:42:53
I noticed that in MVC 2 Preview 2, AreaRegistration is loading the routes for each area in an arbitrary order. Is there a good way to get one before the other? For example, I have two areas - "Site" and "Admin". Both have a "Blog" controller. I would like the following: /admin/ --> go to Admin's Blog controller / --> go to Site's Blog controller. The problem is that it is loading the site's route first, so it is matching {controller}/{action}/{id} instead of admin/{controller}/{action}/{id} when I go to the url "/admin/". I then get a 404, because there is no Admin controller in the "Site"

Make URL language-specific (via routes)

六月ゝ 毕业季﹏ 提交于 2019-11-27 13:12:19
问题 Its hard to find an answer to this specific question, so ill pop it up here: We want to build up our urls completely language specific, meaning www.mysite.com/EN www.mysite.com/DE this is done in the RouteConfig with url: "{language}/{controller}/{action}/{id}" But then the tricky part: www.mysite.com/EN/Categories www.mysite.com/DE/Kategorien I.e. make the controllername appear in a multiple languages, but point to the same controller. Is this even possible? 回答1: Well, this is partially

Plus (+) in MVC Argument causes 404 on IIS 7.0

旧街凉风 提交于 2019-11-27 12:47:53
问题 I have an MVC route that is giving me hell on a staging server running IIS. I am running Visual Studio 2010's development server locally. Here is a sample URL that actually works on my dev box: Root/CPUBoards/Full+Size Results Server Error404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable. Here is the complete behaviour I am seeing. Localhost: Root/CPUBoards/Full Size - Resolves Root/CPUBoards/Full

Getting full url of any file in ASP.Net MVC

孤街浪徒 提交于 2019-11-27 12:23:47
问题 I want to generate complete Url (with domain name etc) of any file in MVC. Example: A .jpg file or an exe file. Example: If I give "~/images/abc.jpg" it should return "http://www.mywebsite.com/images/abc.jpg" I am aware of the Url.Action overload that takes the protocol as a parameter. But Url.Action can be used only for Actions. I want something like Url.Content function that takes protocol as a parameter. Do you know if any method to get complete url of any file? I have tried:

Attribute Routing not working in areas

与世无争的帅哥 提交于 2019-11-27 11:26:28
Scenario: I have a Forms area in my ASP.NET MVC 5 site. I'm trying to redirect to the Details Action which uses a custom route defined using the new Attribute Routing feature. The RedirectToAction: return RedirectToAction("Details", new { slug }); The action I'm redirecting to: [HttpGet] [Route("forms/{slug}")] public ActionResult Details(string slug) { var form = FormRepository.Get(slug); ... return View(model); } I would expect a redirect to http://localhost/forms/my-slug but instead the app is redirecting me to http://localhost/Forms/Details?slug=my-slug . This means that the attribute

How to get current controller and action from inside Child action?

断了今生、忘了曾经 提交于 2019-11-27 11:05:48
I have a portion of my view that is rendered via RenderAction calling a child action. How can I get the Parent controller and Action from inside this Child Action. When I use.. @ViewContext.RouteData.Values["action"] I get back the name of the Child Action but what I need is the Parent/Calling action. Thanks BTW I am using MVC 3 with Razor. And if you want to access this from within the child action itself (rather than the view) you can use ControllerContext.ParentActionViewContext.RouteData.Values["action"] JBeckton Found it... how-do-i-get-the-routedata-associated-with-the-parent-action-in-a

ASP.NET MVC - Extract parameter of an URL

左心房为你撑大大i 提交于 2019-11-27 09:44:37
问题 I'm trying to extract the parameters of my URL, something like this. /Administration/Customer/Edit/1 extract: 1 /Administration/Product/Edit/18?allowed=true extract: 18?allowed=true /Administration/Product/Create?allowed=true extract: ?allowed=true Someone can help? Thanks! 回答1: Update RouteData.Values["id"] + Request.Url.Query Will match all your examples It is not entirely clear what you are trying to achieve. MVC passes URL parameters for you through model binding. public class

ASP.NET MVC - Routing - an action with file extension

喜你入骨 提交于 2019-11-27 09:01:20
is there a way to achieve calling URL http://mywebsite/myarea/mycontroller/myaction.xml This would basically "fake" requesting a file but the result would be an action operation that would serve a file created dynamically? I tried this: context.MapRoute( "Xml_filename", "Xml/{controller}/{action}.xml" ); but whenever there is a filextension in the URL the routing fails and behaves as I was requesting a file directly. I suspect this might be because of using extension less url handler. <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH

ASP.net MVC4 WebApi route with file-name in it

China☆狼群 提交于 2019-11-27 08:14:25
I'm trying to get the following (and similar) urls to work in my ASP.net MVC4/WebApi project: http://127.0.0.1:81/api/nav/SpotiFire/SpotiFire.dll The route responsible for this url looks like this: config.Routes.MapHttpRoute( name: "Nav", routeTemplate: "api/nav/{project}/{assembly}/{namespace}/{type}/{member}", defaults: new { controller = "Nav", assembly = RouteParameter.Optional, @namespace = RouteParameter.Optional, type = RouteParameter.Optional, member = RouteParameter.Optional } ); It works just fine if I remove the . in the file-name, or if I add a slash behind the URL, but that also