Search Results

Search found 202 results on 9 pages for 'maproute'.

Page 4/9 | < Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >

  • Have Microsoft changed how ASP.NET MVC deals with duplicate action method names?

    - by Jason Evans
    I might be missing something here, but in ASP.NET MVC 4, I can't get the following to work. Given the following controller: public class HomeController : Controller { public ActionResult Index() { return View(); } [HttpPost] public ActionResult Index(string order1, string order2) { return null; } } and it's view: @{ ViewBag.Title = "Home"; } @using (Html.BeginForm()) { @Html.TextBox("order1")<br /> @Html.TextBox("order2") <input type="submit" value="Save"/> } When start the app, all I get is this: The current request for action 'Index' on controller type 'HomeController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Index() on type ViewData.Controllers.HomeController System.Web.Mvc.ActionResult Index(System.String, System.String) on type ViewData.Controllers.HomeController Now, in ASP.NET MVC 3 the above works fine, I just tried it, so what's changed in ASP.NET MVC 4 to break this? OK there could be a chance that I'm doing something silly here, and not noticing it. EDIT: I notice that in the MVC 4 app, the Global.asax.cs file did not contain this: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); } which the MVC 3 app does, by default. So I added the above to the MVC 4 app but it fails with the same error. Note that the MVC 3 app does work fine with the above route. I'm passing the "order" data via the Request.Form. EDIT: In the file RouteConfig.cs I can see RegisterRoutes is executed, with the following default route: routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }); I still get the original error, regards ambiguity between which Index() method to call.

    Read the article

  • MVC route doesn't work

    - by bill
    Hi All, I have a bunch of Views in a default folder that represent single "static" pages. Everything works as advertised except i tried adding a new page yesterday.. using the exact same routing syntax and cannot for the life of me get it to work. here's is an example of a working route: routes.MapRoute( "OurProgram", // Route name "Our_Program", // URL with parameters new { controller = "Default", action = "OurProgram" } ); The filename is OurProgram and hitting http:// localhost/Our_Program/ opens the correct view which resides in the Views/Default folder. So i added another view into this folder: Views/Default/BuyNow.aspx and added the route: routes.MapRoute( "BuyNow", // Route name "Buy_Now", // URL with parameters new { controller = "Default", action = "BuyNow" } ); And this doesn't open. I have tried the "route debugger http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx" and it correctly identifies the route. I am at a lose. I have tried re-creating the view.. I am using MVC.Net 2.0 and VS 10. Any help is appreciated!

    Read the article

  • Controller Action Methods with different signatures

    - by Narsil
    I am trying to get my URLs in files/id format. I am guessing I should have two Index methods in my controller, one with a parameter and one with not. But I get this error message in browser below. Anyway here is my controller methods: public ActionResult Index() { return Content("Index "); } // // GET: /Files/5 public ActionResult Index(int id) { File file = fileRepository.GetFile(id); if (file == null) return Content("Not Found"); else return Content(file.FileID.ToString()); } Error: Server Error in '/' Application. The current request for action 'Index' on controller type 'FilesController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Index() on type FileHosting.Controllers.FilesController System.Web.Mvc.ActionResult Index(Int32) on type FileHosting.Controllers.FilesController Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Reflection.AmbiguousMatchException: The current request for action 'Index' on controller type 'FilesController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Index() on type FileHosting.Controllers.FilesController System.Web.Mvc.ActionResult Index(Int32) on type FileHosting.Controllers.FilesController Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [AmbiguousMatchException: The current request for action 'Index' on controller type 'FilesController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Index() on type FileHosting.Controllers.FilesController System.Web.Mvc.ActionResult Index(Int32) on type FileHosting.Controllers.FilesController] System.Web.Mvc.ActionMethodSelector.FindActionMethod(ControllerContext controllerContext, String actionName) +396292 System.Web.Mvc.ReflectedControllerDescriptor.FindAction(ControllerContext controllerContext, String actionName) +62 System.Web.Mvc.ControllerActionInvoker.FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, String actionName) +13 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +99 System.Web.Mvc.Controller.ExecuteCore() +105 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +39 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7 System.Web.Mvc.<c_DisplayClass8.b_4() +34 System.Web.Mvc.Async.<c_DisplayClass1.b_0() +21 System.Web.Mvc.Async.<c__DisplayClass81.<BeginSynchronous>b__7(IAsyncResult _) +12 System.Web.Mvc.Async.WrappedAsyncResult1.End() +59 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +44 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +7 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8677678 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 Updated Code: public ActionResult Index(int? id) { if (id.HasValue) { File file = fileRepository.GetFile(id.Value); if (file == null) return Content("Not Found"); else return Content(file.FileID.ToString()); } else return Content("Index"); } It's still not the thing I want. URLs have to be in files?id=3 format. I want files/3 routes from global.asax routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); //files/3 //it's the one I wrote routes.MapRoute("Files", "{controller}/{id}", new { controller = "Files", action = "Index", id = UrlParameter.Optional} ); I tried adding a new route after reading Jeff's post but I can't get it working. It still works with files?id=2 though.

    Read the article

  • No route in the route table matches the supplied values

    - by Sadegh
    hi i defined some routes in global handler as below routes.MapRoute("Root", "", new { controller = "Root", action = "Default" }); also i created specific controller called RootController which have Default actionResult and return some string. this works fine in vs built-in web-server but An unhandled exception occurred when i sent request rom iis. i'm running this in windows7 ultimate and iis 7.5 integrated-mode and have vs 2008 professional and mvc2 preview2. please help. thank's in advance

    Read the article

  • ASP.NET MVC Html.RouteLink

    - by gilbertc
    I am trying to understand what this RouteLink does. Say, in my Global.asax, I have the default route for MVC routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); and on a View page, I do <%=Html.RouteLink("Dinners", "Default", new { controller="Dinners", action="Details", id="1"} %> Why it does not generate the link /Dinners/Details/1 but thrown an exception? Thanks. Gil.

    Read the article

  • Asp.NET MVC ActionFilter cannot get Form Submit data

    - by Goden
    I want to use custom action filter to manipulate parameters to one action. User inputs: 2 names in a form ; Action: actually needs to take 2 ids; Action Filter (onExecuting, will verify the input names and if valid, convert them into 2 ids and replace in the routedata) because i don't want to put validation logic in Action Controller. here's part of the code: Routing Info routes.MapRoute( "Default", // Route name "{controller}/{action}", // URL with parameters new { controller = "Home", action = "Index"} // Parameter defaults ); routes.MapRoute( "RelationshipResults", // Route Name "Relationship/{initPersonID}/{targetPersonID}", // URL with parameters new { controller = "Relationship", action = "Results" }); Form to submit (Create 2 input box and submit via jquery) <% using (Html.BeginForm("Results", "Relationship", FormMethod.Post, new { id = "formSearch" })) {% ... <td align="left"><%: MvcWeibookWeb.Properties.Resource.Home_InitPersonName%></td> <td align="right"> <%= Html.TextBox("initPersonName")%></td> <td rowspan="3" valign="top"> <div id="sinaIntro"> <%: MvcWeibookWeb.Properties.Resource.Home_SinaIntro %> <br /> <%: MvcWeibookWeb.Properties.Resource.Genearl_PromotionSina %> </div> </td> </tr> <tr> <td align="left" width="90px"><%: MvcWeibookWeb.Properties.Resource.Home_TargetPersonName%></td> <td align="right"><%= Html.TextBox("targetPersonName")%></td> </tr> <tr> <td colspan="2" align="right"> <a href="#" class="btn-HomeSearch" onclick="$('#formSearch').submit();"><%: MvcWeibookWeb.Properties.Resource.Home_Search%></a> </td> Action Filter public override void OnActionExecuting(ActionExecutingContext filterContext) { Sina.Searcher searcher = new Sina.Searcher(Sina.Processor.UserNetwork); String initPersonName, targetPersonName; // form submit names, we need to process them and convert them to IDs before it enters the real controller. initPersonName = filterContext.RouteData.Values["initPersonName"] as String; targetPersonName = filterContext.RouteData.Values["targetPersonName"] as String; // do sth to convert it to ids and replace Action/Controller [ValidationActionFilter] [HandleError] public ActionResult Results( Int64 initPersonName, Int64 targetPersonName) { ... My problem is: in the actionFilter, it never gets the 2 parameter "initPersonName" and "targetPersonName", the RouteData.Values don't contain these 2 keys... :(

    Read the article

  • ASP.NET Routing - load routes from database?

    - by ropstah
    Is it possible to load routes from the database with ASP.NET ? For each r as SomeRouteObject in RouteDataTable routes.MapRoute( _ r.Name, _ r.RouteUri, _ r.RouteValues, _ //?? r.Constraints _ //?? ) Next How should I store the routevalues / constraints? I understand that there are several 'default' routevalues like .Controller and .Action, however I also need entirely custom ones like .Id or .Page...

    Read the article

  • Limit controllers to specific area only

    - by Andrej Kaurin
    I have one Area and in AreaRegistration I defined namespace all controllers in area belongs to. context.MapRoute( "Admin_default", "Admin/{controller}/{action}/{id}", new { controller="Home", action = "Index", id = UrlParameter.Optional }, new[] { "GotSolution.WebSite.Areas.Admin.Controllers" } // Namespaces ); How to prevent controller in that area to be called even when not that route is matched. I.E. /home/index (without "admin" word at the beginning).

    Read the article

  • MVC 2 RC RedirectToAction woes

    - by JonathanTien
    Hiya! I have setup a custom route as defined in my global.asax: routes.MapRoute( "Search", "{controller}/{action}/{type}/{searchterm}", new { controller = "Search", action = "Results", type = "", searchterm = "" } ); Now all I want to do it in a controller when data is passed via POST basically go in the format: http://localhost/Search/Results/2/RG12%201JD Instead what happens is: http://localhost/Search/Results?type=1&searchterm=RG12%201JD What am I doing wrong, the offending code is: return RedirectToAction("Results",new {type = "1", searchterm = "RG12%201JD" }); Any help would be greatly appreciated! Thanks Jonathan

    Read the article

  • where to use route-name of routing in aspnet mvc

    - by FosterZ
    hi,i'm new to routing in aspnet mvc.. i have following code: Action Controller public ActionResult SchoolIndex() { return View(SchoolRepository.GetAllSchools()); } here is the routing routes.MapRoute( "School", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "School", action = "SchoolIndex", id = "" } ); // Parameter defaults when i enter "localhost/school" in addressbar, it is giving 404 error instead it should route to my "schoolIndex" action i have given route-name as "School" where it is used ?

    Read the article

  • ASP.NET MVC Custom Error Pages with Magical Unicorn

    - by FLClover
    my question is regarding Pure.Kromes answer to this post. I tried implementing my pages' custom error messages using his method, yet there are some problems I can't quite explain. a) When I provoke a 404 Error by entering in invalid URL such as localhost:3001/NonexistantPage, it defaults to the ServerError() Action of my error controller even though it should go to NotFound(). Here is my ErrorController: public class ErrorController : Controller { public ActionResult NotFound() { Response.TrySkipIisCustomErrors = true; Response.StatusCode = (int)HttpStatusCode.NotFound; var viewModel = new ErrorViewModel() { ServerException = Server.GetLastError(), HTTPStatusCode = Response.StatusCode }; return View(viewModel); } public ActionResult ServerError() { Response.TrySkipIisCustomErrors = true; Response.StatusCode = (int)HttpStatusCode.InternalServerError; var viewModel = new ErrorViewModel() { ServerException = Server.GetLastError(), HTTPStatusCode = Response.StatusCode }; return View(viewModel); } } My error routes in Global.asax.cs: routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); routes.MapRoute( name: "Error - 404", url: "NotFound", defaults: new { controller = "Error", action = "NotFound" } ); routes.MapRoute( name: "Error - 500", url: "ServerError", defaults: new { controller = "Error", action = "ServerError" } ); And my web.config settings: <system.web> <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="/ServerError"> <error statusCode="404" redirect="/NotFound" /> </customErrors> ... </system.web> <system.webServer> <httpErrors errorMode="Custom" existingResponse="Replace"> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" path="/NotFound" responseMode="ExecuteURL" /> <remove statusCode="500" subStatusCode="-1" /> <error statusCode="500" path="/ServerError" responseMode="ExecuteURL" /> </httpErrors> ... The Error views are located in /Views/Error/ as NotFound.cshtml and ServerError.cshtml. b) One funny thing is, When a server error occurs, it does in fact display the Server Error view I defined, however it also outputs a default error message as well saying that the Error page could not be found. Here's how it looks like: Do you have any advice how I could fix these two problems? I really like Pure.Kromes approach to implementing these error messages, but if there are better ways of achieving this don't hestitate to tell me. Thanks! *EDIT : * I can directly navigate to my views through the ErrorController by accessing /Error/NotFound or Error/ServerError. The views themselves only contain some text, no markup or anything. As I said, it actually works in some way, just not the way I intended it to work. There seems to be an issue with the redirect in the web.config, but I haven't been able to figure it out.

    Read the article

  • how to pass querystring in friendly url in asp.net mvc

    - by frosty
    I have the following action. I can hit this with /basket/address?addressId=123 However i wonder how i can hit it with /basket/address/123 public ActionResult Address(int addressId) { return RedirectToAction("Index"); } my routes routes.MapRoute( "Default", // Route name "{controller}.aspx/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults );

    Read the article

  • ASP MVC - Getting Controller Level error handling

    - by RP
    How to get Controller-Level error handling: This is my map-route: routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); And I have 2 controllers - HomeController and AwayController I want both both controllers to handle their own errors For example, a call to /Home/InvalidAction would be handled by one method and /Away/InvalidAction would be handled by another method Where InvalidAction currently results in a 404 as there's no Action method with that name

    Read the article

  • How to create route

    - by user276640
    I want to use URL such as /Image/sample.png I create route, but it does not work, it say "The resource cannot be found" What is the problem? (action GetImage is in controller home) routes.MapRoute("Image", "Image/{id}", new { controller = "Home", action = "GetImage", id = "" });

    Read the article

  • use viewengine only within certain area

    - by Daniel Powell
    Is it possible to use a custom view engine for a specific area only? I have tried public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Forms_default", "Forms/{client}/{controller}/{action}/{id}", new { client="Generic",action = "Index", id = UrlParameter.Optional } ); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new ClientSpecificViewEngine()); } Within my area but this seems to be a site wide affect as I'm getting errors specific to the custom view engine when visiting pages outside the area.

    Read the article

  • What Controller/Action will this go to?

    - by rkrauter
    Assume this is the first route entry: routes.MapRoute( "myRoute", "employees/{city}/{pageNumber}", new { controller="Employees", action = "List", pageNumber = 1 } ); If I make the following request employees/london/2 it gets matched to the following action method: public ActionResult List(string city) {} How did that happen? I did not specify "city" in my object defaults: new { controller="Employees", action = "List", pageNumber = 1 } Please explain. Thanks!

    Read the article

  • Can I constrain a route parameter to a certain type in ASP.net MVC?

    - by Paul Suart
    I have the following route: routes.MapRoute( "Search", // Route name "Search/{affiliateId}", // URL with parameters new { controller = "Syndication", action = "Search" } // Parameter defaults ); Is there a way I can ensure "affiliateId" is a valid Guid? I'm using MVCContrib elsewhere in my site and I'm fairly it provides a way to implement this kind of constraint.... I just don't know what it is!

    Read the article

  • ASP.NET MVC Default URL View

    - by Moose Factory
    I'm trying to set the Default URL of my MVC application to a view within an area of my application. The area is called "Common", the controller "Home" and the view "Index". I've tried setting the defaultUrl in the forms section of web.config to "~/Common/Home/Index" with no success. I've also tried mapping a new route in global.asax, thus: routes.MapRoute( "Area", "{area}/{controller}/{action}/{id}", new { area = "Common", controller = "Home", action = "Index", id = "" } ); Again, to no avail.

    Read the article

  • Deploy .net MVC 2 appication on IIS6

    - by munish
    I want to deploy my .net MVC 2 appication on IIS6.0. Will it require to change route path in global.asax file. In my application i have used html link, ajax request and Html.ActionLink. The code lines in the Global.asax file are: routes.MapRoute( "LogOn", "{controller}/{action}/{id}", new { controller = "Account", action = "Index", id = UrlParameter.Optional } ); Please suggest me. Thanks and Regards Munish

    Read the article

  • How to remove index from url in asp.net mvc?

    - by Pandiya Chendur
    I am doing a return RedirectToAction("Index", "Clients"); from my home controller.... It is fine but my url looks like http://localhost:1115/Clients/Index... How to remove index from url in asp.net mvc? Any suggestion.... My routes, public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Registrations", "{controller}/{action}/{id}", new { controller = "Registration", action = "Create", id = "" } ); }

    Read the article

  • ASP.NET MVC routing issue: How to allow "\" in id's

    - by Bipul
    I am using following route map routes.MapRoute( "RenderAssociatedForm", "DoAction/{nodeLevelId}/{nodeSystemId}", new { controller = "FrontEnd", action = "RenderAssociatedForm", }); Now nodeLevelId can be anything like zs\bbal. As we know that we should escape '\', so we are using 'zs%5cbbal'. But still the following url is not mapping to this route. //localhost/DoAction/zs%5cbbal/5 When I try simple Id without the escape character, it maps properly. Can anybody tell me where I am going wrong?

    Read the article

  • How Do I get City State Zip in MVC 3 URL Route without writing a controller for every state and actions for each city

    - by OpTech Marketing
    I have the need to have the urls in my bosses application look like: http://domain.com/Texas/Dallas/72701 However, I don't want to write a controller for every state and an action for every city. routes.MapRoute( "DrillDown", // Route name "{controller}/{action}/{ZipId}", new { controller = "State", action = "City", ZipId = UrlParameter.Optional} // Parameter defaults Can someone help me write a pattern for the routes that will accept State/City/Zip without destroying the ability for me to have regular routes with controller/Action/Param ? Looking all over and can't find any direction.

    Read the article

  • ASP.NET MVC 2 Preview 2 Route Request Not Working

    - by Kezzer
    Here's the error: The incoming request does not match any route. Basically I upgraded from Preview 1 to Preview 2 and got rid of a load of redundant stuff in relation to areas (as described by Phil Haack). It didn't work so I created a brand new project to check out how its dealt with in Preview 2. The file Default.aspx no longer exists which contains the following: public void Page_Load(object sender, System.EventArgs e) { // Change the current path so that the Routing handler can correctly interpret // the request, then restore the original path so that the OutputCache module // can correctly process the response (if caching is enabled). string originalPath = Request.Path; HttpContext.Current.RewritePath(Request.ApplicationPath, false); IHttpHandler httpHandler = new MvcHttpHandler(); httpHandler.ProcessRequest(HttpContext.Current); HttpContext.Current.RewritePath(originalPath, false); } The error I received points to the line httpHandler.ProcessRequest(HttpContext.Current); yet in newer projects none of this even exists. To test it, I quickly deleted Default.aspx but then absolutely nothing worked, I didn't even receive any errors. Here's some code extracts: Global.asax.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace Intranet { public class MvcApplication : System.Web.HttpApplication { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); AreaRegistration.RegisterAllAreas(); routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" } ); } protected void App_Start() { RegisterRoutes(RouteTable.Routes); } } } Notice the area registration as that's what I'm using. Routes.cs using System.Web.Mvc; namespace Intranet.Areas.Accounts { public class Routes : AreaRegistration { public override string AreaName { get { return "Accounts"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute("Accounts_Default", "Accounts/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" }); } } } Check the latest docs for more info on this part. It's to register the area. The Routes.cs files are located in the root folder of each area. Cheers

    Read the article

  • Url routing issue in asp.net mvc ...

    - by Pandiya Chendur
    I am doing a return RedirectToAction("Index", "Clients"); from my home controller.... It is fine but my url looks like http://localhost:1115/Clients/Index... How to remove index from url in asp.net mvc? Any suggestion.... My routes, public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Registrations", "{controller}/{action}/{id}", new { controller = "Registration", action = "Create", id = "" } ); }

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >