asp.net-mvc-routing

Task async controller method does not hit

▼魔方 西西 提交于 2019-12-07 04:21:27
问题 So, we've got an MVC project that has been upgraded through the different versions of MVC from 1 through to 4. Now we have a controller method: public async Task<ActionResult> IndexAsync() so if we go to http://somedomain.xyz/WhicheverController or http://somedomain.xyz/WhicheverController/Index , we are greeted with a 404. http://somedomain.xyz/WhicheverController/IndexAsync routes to the method just fine. What's gone wrong with our routing? 回答1: I believe that your example will work if you

Passing multiple parameters from url to html.actionlink

你。 提交于 2019-12-07 03:09:40
问题 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

MVC 3 tries to launch URL to View instead of controller action

 ̄綄美尐妖づ 提交于 2019-12-07 02:21:36
问题 Sometimes when I launch my MVC 3 project it attempts to load the fully qualified URL for the view being rendered instead of the action within the controller (Which gives me a 404 error). Other times it works fine and actually hits the controller action like it's supposed to, but it's about 50/50. The URL it hits sometimes is: http://localhost:xxxx/Views/Account/LogOn.cshtml Here is the default route setup in the Global.asax file: routes.MapRoute( "Default", // Route name "{controller}/{action

Ambiguous Actions

旧城冷巷雨未停 提交于 2019-12-07 02:21:29
Is there any way to have multiple actions with different parameters? I've seen it using the HttpPost verbs flag, but it doesn't seem to work for me in other places. The current request for action List on controller type FoldersController` is ambiguous between the following action methods. public ActionResult List() { //... } public ActionResult List(DateTime start) { // ... } public ActionResult List(string key) { // .... } Trying this Route Paramter I found on ... I'm still a bit confused about how the routing works. This is what I have so far. ASP.NET MVC Routing Via Method Attributes But I

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

不羁的心 提交于 2019-12-07 00:07:36
问题 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? 回答1: 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

Ignoring a route in ASP.NET MVC

爱⌒轻易说出口 提交于 2019-12-06 18:42:32
问题 I am just learning to work with routing in ASP.NET MVC and am trying to understand the IgnoreRoute method. I am trying to prevent users from accessing "Content/{filename}.html" . I have placed this as the first call in my RegisterRoutes method. Here is my code: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("Content/{filename}.html"); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute("MyRoute", "{controller}/{action}/{id}/{*catchall}", new {

controller path not found for static images? asp.net mvc routing issue?

醉酒当歌 提交于 2019-12-06 18:19:21
问题 I have an image folder stored at ~/Content/Images/ I am loading these images via <img src="/Content/Images/Image.png" /> Recently, the images aren't loading and I am getting the following errors in my error log. What's weird is that some images load fine, while others do not load. Anyone have any idea what is wrong with my routes? Am I missing an ignore route for the /Content/ folder? I am also getting the same error for favicon.ico and a bunch of other image files... <Fatal> -- 3/25/2010 2

Can you pass a model with RedirectToAction?

萝らか妹 提交于 2019-12-06 17:40:40
问题 I'm using mvc 2 release candidate, and am wondering if there's any way to pass a model to an action using RedirectToAction. For example, I have an edit action which takes an ID, and loads the record from a database, displays the current values in text boxes and lets the user edit and click submit: public ActionResult Edit(int ID) Then I have an edit action for the HttpPost which takes a model and updates the database: [HttpPost] public ActionResult Edit(Administration.Models

How do I change the order of routes.MapRoute in MVC3?

大城市里の小女人 提交于 2019-12-06 16:55:16
How do I change the order of the url parameter when registering routes in global.asax.cs? I registered the route like so: (Note: I also have the default MVC3 route registered as well) routes.MapRoute( "SurveyWizard", "survey/{id}/{action}", new { id = UrlParameter.Optional, action = "AddQuestions" }); My controller: public ActionResult AddQuestions(int id) { if(id < 1 || id == null) //Redirect somewhere var survey = _surveyService.GetSurveyById(id); //other controller logic return View(survey); } When I type the url .../survey/1/AddQuestions the resource can't be found. When I run a route

What's the WebApi [FromUri] equivalent in ASP.NET MVC?

巧了我就是萌 提交于 2019-12-06 16:51:12
问题 In WebApi I can decorate a parameter on a controller action with [FromUri] to have the components of the URI 'deserialized', if you will, into a POCO model; aka model-binding. Despite using MVC since 2.0, I've never used it for websites (dunno why). What's the equivalent of it in ASP.NET MVC 5? The attribute doesn't seem to be recognised in the IDE unless I need to reference a library. I'd like ~/thing/2014/9 to bind to the model below: public class WhateverModel { public int Year { get; set;