asp.net-mvc-routing

ASP.NET MVC: routing help

五迷三道 提交于 2019-12-11 10:13:30
问题 Consider two methods on the controller CustomerController.cs : //URL to be http://mysite/Customer/ public ActionResult Index() { return View("ListCustomers"); } //URL to be http://mysite/Customer/8 public ActionResult View(int id) { return View("ViewCustomer"); } How would you setup your routes to accommodate this requirement? How would you use Html.ActionLink when creating a link to the View page? 回答1: In global.asax.cs, add following (suppose you use the default mvc visual studio template)

Can we dynamically change the URL with Ajaxy call on ASP.NET MVC page?

送分小仙女□ 提交于 2019-12-11 09:47:24
问题 I have an ASP.NET MVC application that has a view called Products. This Products View has a Left Menu Navigation that is implemented using NavMenuProducts.ascx Partial View. This Menu is implemented using JQuery Treeview so that it has the list of ProductNames as the Parent Node and it is expandable(For Example: 10 Products). Each of these Products have a ChildNode as DocTypeName and it is a hyperlink(For Example: 3 DocTypeNames). When the user clicks ChildNode Hyperlink all the matching

Why is my Web API server refusing to accept calls from Android?

喜欢而已 提交于 2019-12-11 09:19:49
问题 I can access my Web API server from a Windows app without problems. From Android, though, is a different story Why would that be? Is "localhost" the wrong thing to use (in the URL)? Should I use the name of the computer instead? Does the string (passed literally as " http://localhost:28642/api/Departments/GetCount?serialNum=4242 ") need to be verbatimized? What is the difference between a Windows app calling a REST method, and an Android app calling the same REST method, that would cause the

IIS 7 URL Rewrite config issue or MVC Route?

有些话、适合烂在心里 提交于 2019-12-11 06:48:55
问题 I have an account with Gearhost.com and when it comes to setting up sub-domains you are currently required to go in and configure an URL Rewrite entry using IIS Remote Admin. The directory folder structure follows the pattern: \mastersite \mastersite\subdomain1 The Gearhost KB Article on how to do it can be found here: https://support.gearhost.com/KB/a851/setting-a-subdomains-content-location-using-url-rewrite.aspx?KBSearchID=0 This works just fine, but I ran into a scenario that revealed the

ASP.net MVC 4, How to keep routing to default document after project publishing

≯℡__Kan透↙ 提交于 2019-12-11 06:39:31
问题 I created a new MVC 4 project from the internet application template in VS 2012 express, for details click here When I wanted to publish it, I got: HTTP 403.14 - Forbidden I searched for a solution, and found that it looks like a routing issue, other posts in stackoverflow give answers through modifying MVC 3 global.asax instructions. when I tried to apply the same solution to the MVC 4 global.asax I found syntaxes too different from those of MVC 3, i.e. RouteConfig.RegisterRoutes(RouteTable

ActionLink is showing query string instead of URL parameters

倖福魔咒の 提交于 2019-12-11 06:07:22
问题 My question is very similar other questions. When using an ActionLink in MVC .Net 4.5, I am getting a query string for one parameter, instead of just a URL path. I tried the solution HERE, but it did not work. CODE- Inside RouteConfig.cs - routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); routes.MapRoute( name: "MyControllerRoute", url: "{controller}/{action}/{id}/{description}", defaults

Refactoring an algorithm

六月ゝ 毕业季﹏ 提交于 2019-12-11 04:52:40
问题 I'm trying to re-implement ASP.NET MVC routing rules in C++ for my own MVC application. Currently the code takes at least O(N) at best case and more if accessing the controller/action inside an unordered_map is not O(1) . I would like my code to prefer a route with a controller that's already in the URI, for instance if the current URI is 'projects/2/show' and I have '[Controller]/[Action]/[ID]/' , '[Controller]/[ID]/[Action]/' , 'projects/[ID]/[Action]/' and 'projects/[ID]/show' I prefer the

How to hide action and controller from url : asp.net mvc [duplicate]

不羁岁月 提交于 2019-12-11 04:09:43
问题 This question already has answers here : Routing in ASP.NET MVC, showing username in URL (2 answers) Closed 3 years ago . Introduction I am working on demo application where users can register.Users table have "username" field.There is "detail" action in "home" controller accepting parameter of string "username". Code public ActionResult Detail (string username) { return View(); } Then url will be www.example.com/home/Detail?username=someparam Problem Can i setup route like that ? www.example

Html.BeginRouteForm doesn't generate URL for named route

橙三吉。 提交于 2019-12-11 04:02:01
问题 I am attempting to use Html.BeginRouteForm to generate the action for a form in my ASP.NET MVC app. The route I am targeting is: //CREATE routes.MapRoute("map-config-post", "projects/{projectId}/mapconfigs", new { controller = controllerName, action = "Create" }, new { httpMethod = new RestfulHttpMethodConstraint("POST") }); Unit testing and following the route in the app is successful. Now, I would like to create an HTML form with this route is it's URL: @using (Html.BeginRouteForm("map

Is is possible to make SEO friendly Url's in ASP.NET Core like this one

有些话、适合烂在心里 提交于 2019-12-11 03:54:36
问题 I wanted to ask you guys if is it possible, to make some routing like this for my project /{action}/{title} ? I was wondering if that is possible, does this url has to be a primary key too? Since there is no ID passed to know which blog post is this. Thank you. 回答1: You can do this quite easily with attribute routing: [Route("blogs")] public class BlogController { [AcceptVerbs("GET", "HEAD", Route = "{slug}")] public IActionResult View(string slug) { } } This maps all requests to /blogs