asp.net-mvc-routing

Handling MVC2 variables with hyphens in their name

三世轮回 提交于 2019-12-05 08:07:01
I'm working with some third-party software that creates querystring parameters with hyphens in their names. I was taking a look at this SO question and it seems like their solution is very close to what I need but I'm too ignorant to the underlying MVC stuff to figure out how to adapt this to do what I need. Ideally, I'd like to simply replace hyphens with underscores and that would be a good enough solution. If there's a better one, then I'm interested in hearing it. An example of a URL I want to handle is this: http://localhost/app/Person/List?First-Name=Bob&My-Age=3 with this Controller:

Passing multiple parameters from url to html.actionlink

走远了吗. 提交于 2019-12-05 06:43:27
I'm fairly new to MVC and am struggling with routing when I try to pass multiple parameters via the URL. From a page with the URL: /PersonCAFDetail/Index/3?memberid=4 ...I'm trying to get an Html.ActionLink set to point to the Create action such that the id=3 and the memberid=4. Having read a number of similar posts it seems that the following should work: @Html.ActionLink("Create New", "Create", null, new { memberid = "memberid" }) However, this results in a URL being created as follows: <a href="/PersonCAFDetail/Create/3" memberid="memberid">Create New</a> I have a route set up as: routes

Creating Canonical URLs including an id and title slug

感情迁移 提交于 2019-12-05 06:26:14
问题 I want to replicate what StackOverflow does with its URLs. For example: Hidden Features of C#? - (Hidden Features of C#?) or Hidden Features of C#? - (Hidden Features of C#?) Will Take you to the same page but when they return to the browser the first one is always returned. How do you implement the change so the larger URL is returned? 回答1: The way that I've handled this before is to have two routes, registered in this order routes.MapRoute( null, "questions/{id}/{title}", new { controller =

When to use a routing rule vs query string parameters with asp.net mvc

梦想与她 提交于 2019-12-05 05:37:33
We're considering moving forward with a ASP.NET MVC project and the subject of routing versus parameters came up. Seeing as how you can easily set up either or a combination of both in ASP.NET MVC, are there any considerations that I should be aware of when using one or the other? amurra I would recommend keeping your URL's as clean as possible and to try and use routes whenever possible. You should try and make RESTful URI's that will convey information to the user. For example: www.yourdomain.com/Products/Sports/Clothing is a lot cleaner than www.yourdomain.com/Products?Department=Sports

.net Core - Default controller is not loading when Route attribute is used

回眸只為那壹抹淺笑 提交于 2019-12-05 04:52:40
A new .net core web application project comes with the following route configuration: app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); If you replace this with app.UseMvc() and add appropriate Route attributes for both HomeController and its actions (Index, About, Contact, Error), it would still work. Since we're not specifying a default route, the default view (Home/Index) will not be rendered if you hit http://localhost:25137/ . Hope that understanding is correct! Now, since I need the default view to be shown when the http:/

Getting MVC to ignore route to site root

故事扮演 提交于 2019-12-05 03:41:51
I'm working on a site that is partially static content and partially MVC. The root of the site is index.html and I have all of the controllers explicitly routed and all html files ignored. However, when you hit the root of the website, it tries to route it. How can I tell the route engine to ignore the root of the site? www.mysite.com should not be routed, but instead go to index.html. Here is my routing configuration: routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("*.html|js|css|gif|jpg|jpeg|png|swf"); routes.MapRoute( "vendor_signup","{vendor}/signup/{action}/", new {

Dynamic routing in ASP.Net Core

痴心易碎 提交于 2019-12-05 01:57:52
问题 I need to provide a routing mechanic where the routes are generated at runtime from user account creations. Such as http://mysite/username/home . I assume this can be done via routing but i'm not sure where to get started on it with ASP.Net Core. I've seen some examples online for MVC 5 but ASP.Net Core seems to handle routing a little bit differently. How can I ensure that the site doesn't get confused between http://mysite/username/news being the users custom landing page and http://mysite

MVC API Routing When Multiple Get Actions Are Present

风格不统一 提交于 2019-12-05 01:30:29
问题 There seems to be a thousand people asking the same question on stack overflow, but there doesn't seem to be a single solution to this problem. I am going to ask it again... I have an API controller that has the following actions: // GET api/Exploitation public HttpResponseMessage Get() { var items = _exploitationRepository.FindAll(); var mappedItems = Mapper.Map<IEnumerable<Exploitation>, IEnumerable<ExploitationView>>(items); var response = Request.CreateResponse<IEnumerable

MVC Routes within WebAPI controller

眉间皱痕 提交于 2019-12-05 00:49:09
问题 Quick question regarding routes within MVC and WebAPI. I have added a route to route config.cs: routes.MapRoute( name: "ConfirmEmail", url: "ConfirmEmail/{userid}", defaults: new { controller = "Email", action = "ConfirmEmail" } ); This is registered in the global.asax as per normal: RouteConfig.RegisterRoutes(RouteTable.Routes); I am trying to generate a URL for use within an email which is sent as part of a function call within a WebAPI controller function. I am using the UrlHelper.Link

Should I use RouteParameter or UrlParameter for an Asp.NET web-api route?

烈酒焚心 提交于 2019-12-05 00:44:38
I've seen both being used and so I wonder, do they do the same thing or different things? If it's the latter, what's the difference? I tried answering it myself by having a look at the visual studio MVC 4 (rc) web api template, but sadly it uses both, so my confusion remains. Here's what the template contains: public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); routes.MapRoute(