asp.net-mvc-routing

Route with Two optional parameters in MVC3 not working

心已入冬 提交于 2019-11-26 17:49:17
问题 I have a following types of url used in my Application. localhost/admin/userdetail/id localhost/admin/userdetail/id/true localhost/admin/userdetail/id/true/success Here is my Admin Controller bool inSaveAction, string status are optional [Authorize] public ActionResult UserDetail(string Id, bool inSaveAction, string status) { } [HttpPost, Authorize, ValidateAntiForgeryToken] public ActionResult SaveUserDetail(UserDetailViewModel viewModel) { User userToSave = new User(); AdminService

Asp.Net Routing - Display complete URL

独自空忆成欢 提交于 2019-11-26 17:26:09
问题 I have a domain "http://www.abc.com". I have deployed an ASP.net MVC4 app on this domain. I have also configured a default route in RouteConfig.cs as shown below routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "MyApp", action = "Home", id = UrlParameter.Optional } ); The above mapping ensures that anyone attempting to visit "http://www.abc.com" is automatically shown the page for "http://www.abc.com/MyApp/Home" Everything works as expected but

WebAPI route 404's when there is a trailing space in the URL

社会主义新天地 提交于 2019-11-26 17:03:58
问题 With the default web api route config.Routes.MapHttpRoute( name: "API Default", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); and a controller public class TestController : ApiController { [HttpGet] public HttpResponseMessage Get(string id) { return Request.CreateResponse(HttpStatusCode.OK, id); } } A request to 'api/test/1' returns 1 If for some reason you send a request to 'api/test/1%20' the route 404's. Now this example may seem silly since

ASP.Net MVC RouteData and arrays

流过昼夜 提交于 2019-11-26 16:06:57
问题 If I have an Action like this: public ActionResult DoStuff(List<string> stuff) { ... ViewData["stuff"] = stuff; ... return View(); } I can hit it with the following URL: http://mymvcapp.com/controller/DoStuff?stuff=hello&stuff=world&stuff=foo&stuff=bar But in my ViewPage, I have this code: <%= Html.ActionLink("click here", "DoMoreStuff", "MoreStuffController", new { stuff = ViewData["stuff"] }, null) %> Unfortunately, MVC is not smart enough to recognize that the action takes an array, and

ASP.Net MVC Handling Segments with Route

我怕爱的太早我们不能终老 提交于 2019-11-26 15:33:00
I am new to ASP.Net MVC and facing a problem. Here it is. routes.MapRoute( "SearchResults",// Route name "{controller}/{action}/{category}/{manufacturer}/{attribute}", new { controller = "Home", action = "CategoryProducts", category = UrlParameter.Optional, manufacturer = UrlParameter.Optional, attribute = UrlParameter.Optional } ); And here is my controller method. public ActionResult CategoryProducts(string category, string manufacturer, string attribute) { string[] categoryParameter = category.Split('_'); . . . return View(); } when i hit the url i always get null in category parameter http

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

假装没事ソ 提交于 2019-11-26 15:25:34
问题 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. 回答1: And if you want to access this from within the child action itself (rather than the view) you can use ControllerContext.ParentActionViewContext

URLs with slash in parameter?

眉间皱痕 提交于 2019-11-26 15:21:23
Question: I am creating a wiki software, basically a clone of wikipedia/mediawiki, but in ASP.NET MVC (the MVC is the point, so don't recommend me ScrewTurn). Now I have a question: I use this route mapping, to route a URL like: http://en.wikipedia.org/wiki/ASP.NET routes.MapRoute( "Wiki", // Routenname //"{controller}/{action}/{id}", // URL mit Parametern "wiki/{id}", // URL mit Parametern new { controller = "Wiki", action = "dbLookup", id = UrlParameter.Optional } // Parameterstandardwerte ); Now it just occured to me, that there might be titles like 'AS/400': http://en.wikipedia.org/wiki/AS

Change route collection of MVC6 after startup

谁说我不能喝 提交于 2019-11-26 15:20:12
In MVC-5 I could edit the routetable after initial startup by accessing RouteTable.Routes . I wish to do the same in MVC-6 so I can add/delete routes during runtime (usefull for CMS). The code to do it in MVC-5 is: using (RouteTable.Routes.GetWriteLock()) { RouteTable.Routes.Clear(); RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); RouteTable.Routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } But I can't find RouteTable.Routes or something similar in MVC-6. Any idea how I can

How to reuse Areas, Controllers, Views, Models, Routes in multiple apps or websites

可紊 提交于 2019-11-26 14:46:55
问题 I have a test solution which only has one area called Admin. I would like to reuse Admin across a number of other web applications. I have a web application setup in IIS, I have then added a virtual application, /Admin coming from Areas\Admin . When I navigate to /Admin, I see a directory listing. When I try to hit a controller, /Admin/News. I get a 404 error. It could be that the areas are not registering, even though the code is there in the global.asax. However, I am sure I am going about

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

你说的曾经没有我的故事 提交于 2019-11-26 14:05:31
问题 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