asp.net-mvc-routing

ASP.NET MVC ambiguous action methods

早过忘川 提交于 2019-11-26 14:01:40
I have two action methods that are conflicting. Basically, I want to be able to get to the same view using two different routes, either by an item's ID or by the item's name and its parent's (items can have the same name across different parents). A search term can be used to filter the list. For example... Items/{action}/ParentName/ItemName Items/{action}/1234-4321-1234-4321 Here are my action methods (there are also Remove action methods)... // Method #1 public ActionResult Assign(string parentName, string itemName) { // Logic to retrieve item's ID here... string itemId = ...; return

jQuery Mobile/MVC: Getting the browser URL to change with RedirectToAction

自闭症网瘾萝莉.ら 提交于 2019-11-26 12:59:17
问题 My first post... When I use RedirectToAction the url in the browser doesn\'t change. How can I achieve this? I\'m switching over to ASP.NET MVC 3.0 (also using jQuery Mobile) after 10+ years using web forms. I\'m about 8 weeks into it, and after several books and scouring Google for an answer, I\'m coming up dry. I have a single route defined in Global.asax: routes.MapRoute( \"Routes\", \"{controller}/{action}/{id}\", new { controller = \"Shopping\", action = \"Index\", id = UrlParameter

Set “Homepage” in Asp.Net MVC

戏子无情 提交于 2019-11-26 12:57:30
问题 In asp.net MVC the \"homepage\" (ie the route that displays when hitting www.foo.com) is set to Home/Index . Where is this value stored? How can I change the \"homepage\"? Is there anything more elegant than using RedirectToRoute() in the Index action of the home controller? I tried grepping for Home/Index in my project and couldn\'t find a reference, nor could I see anything in IIS (6). I looked at the default.aspx page in the root, but that didn\'t seem to do anything relevent. Thanks 回答1:

Implementing “Remember Me” Feature in ASP.NET MVC

孤街醉人 提交于 2019-11-26 12:53:33
问题 I\'m trying to implement a \"remember me\" feature to my login form. I am using ASP.NET MVC as my web application. I managed to get the cookie stuff working, but I failed to automatically login the user in case he/she checked the remember me checkbox before. I know what the problem is but I do not know how to solve it. In my HomeController I have the following: private LoginViewModel CheckLoginCookie() { if (!string.IsNullOrEmpty(_appCookies.Email) && !string.IsNullOrEmpty(_appCookies

How to use an Area in ASP.NET Core

戏子无情 提交于 2019-11-26 12:08:30
问题 How do I use an Area in ASP.NET Core? I have an app that needs an Admin section. This section requires its Views to be placed in that area. All requests that start with Admin/ will need to be redirected to that area. 回答1: In order to include an Area in an ASP.NET Core app, first we need to include a conventional route in the Startup.cs file (It's best to place it before any non-area route): In Startup.cs/Configure method: app.UseMvc(routes => { routes.MapRoute("areaRoute", "{area:exists}/

Ensure that HttpConfiguration.EnsureInitialized()

一世执手 提交于 2019-11-26 12:03:12
问题 I\'ve installed Visual Studio 2013 and when I run my app I get the error below. I\'ve got no idea as to where I\'m to initialized this object. What to do? Server Error in \'/\' Application. The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application\'s startup code after all other initialization code. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more

How do you request static .html files under the ~/Views folder in ASP.NET MVC?

半世苍凉 提交于 2019-11-26 11:16:21
I want to be able to request static .html files which are located in the ~/Views folder. According to the documentation, the routing system checks to see if a URL matches a disk file before evaluating the application's routes. But when I request the file a 404 error arises. My file is located in ~/Views folder. The URL is: http://[localhost]/Views/HtmlPage1.html What have I missed? Darin Dimitrov I want to be able to request static .html files which are located in the '~/Views' folder. You can't. There's a web.config file in this folder which explicitly forbids accessing any file from it. If

asp.net mvc complex routing for tree path

有些话、适合烂在心里 提交于 2019-11-26 10:28:59
问题 I am wondering how can I define a routing map like this: {TreePath}/{Action}{Id} TreeMap is dynamically loaded from a database like this: \'Gallery/GalleryA/SubGalleryA/View/3\' 回答1: You can create a custom route handler to do this. The actual route is a catch-all: routes.MapRoute( "Tree", "Tree/{*path}", new { controller = "Tree", action = "Index" }) .RouteHandler = new TreeRouteHandler(); The tree handler looks at path, extracts the last part as action, and then redirects to the controller.

mvc Html.BeginForm different URL schema

旧城冷巷雨未停 提交于 2019-11-26 10:01:47
问题 I\'m creating a form for a DropDown like this: @{ Html.BeginForm(\"View\", \"Stations\", FormMethod.Get); } @Html.DropDownList(\"id\", new SelectList(ViewBag.Stations, \"Id\", \"Name\"), new { onchange = \"this.form.submit();\" }) @{ Html.EndForm(); } If I choose a value from my dropdown I get redirected to the correct controller but the URL is not as I would like to have it: /Stations/View?id=f2cecc62-7c8c-498d-b6b6-60d48a862c1c What I want is: /Stations/View/f2cecc62-7c8c-498d-b6b6

How to change route to username after logged in?

白昼怎懂夜的黑 提交于 2019-11-26 09:58:33
问题 Before user login, the route is: localhost:54274/Home localhost:54274/Home/About localhost:54274/Home/Contact localhost:54274/Home/Login localhost:54274/Home/Register Once after user logged in, the route is: 1. localhost:54274/Project 2. localhost:54274/Project/Create 3. localhost:54274/Project/Edit/1 4. localhost:54274/Project/Delete/2 5. localhost:54274/Project/1/Requirement 6. localhost:54274/Project/1/Requirement/Create 7. localhost:54274/Project/1/Requirement/Edit/3 8. localhost:54274