MVC :: RedirectToAction Failing To Match Default Route In MVC3
Jan 27, 2011
I have a Search Controller with an action method as follows:
public ActionResult Location(LocationSearchInputModel input)
{
// Get Results and pass cacheId in TempData
return RedirectToAction("results");
}
public ActionResult Results()
{
// Get cacheId from TempData and build Model
return View(model);
}
The call to RedirectToAction fails with the following error message:
Message: No route in the route table matches the supplied values.
My default Route is set up as follows:
routes.MapRoute(null, "{controller}.mvc/{action}/{id}/", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
As the id Parameter in the default Route is optional shouldn't RedirectToAction("results") execute the SearchController's Results action?
It worked in MVC2 :/
View 5 Replies
Similar Messages:
Mar 8, 2011
I use the RedirectToAction with parameters in my action method
return RedirectToAction("ListThreads", "View", new { category = "1", subcategory = "49"});
After redirect the url comes out like this
http://domain/Forum/View/ListThreads?category=1&subcategory=49
I want it to be generated like
http://domain/Forum/View/ListThreads/1/49
How to do it?
Note : I already have a route in global.asax that is used by all the pages/links.
context.MapRoute(
"Forum_subcategory",
"Forum/{controller}/{action}/{category}/{subcategory}",
new { controller = "View", action = "ListThreads", category = "", subcategory = "" }
);
View 1 Replies
Dec 17, 2010
I'm baffled as to why this error keeps popping up all the time....
i've created handlers in IIS7 to map requests for static content.
I've added the following line to my routes:
routes.IgnoreRoute("rest/schema/{file}.xsd");
I've checked that the file is physicly present on the location, yet MVC keeps bitching about not beeing able to find a route. What is the IgnoreRoute for then if it keeps searching?
View 3 Replies
Jun 11, 2010
i have published asp.net mvc application on iis 6 on the server(windows server 2003) from local machine. On server i have set the default page to default.aspx. but when i try to browse the site on server, it gives me exception "The incoming request does not match any route" One thing i noticed is that. Stack trace on line 5 is shown below. it has one weird thing that exception is still pointing to my local machine path
[code]....
View 2 Replies
May 7, 2010
I am using asp.net C#/3.5 and stuck.
PHP Code:
Route myroute1 = new Route("{controller}/{action}/{slug}", new MyRouteHandler());
Route myroute2 = new Route("{controller}/{action}", new MyRouteHandler());
Route myroute3 = new Route("{controller}", new MyRouteHandler());
Routes.Add(myroute1);
Routes.Add(myroute2);
Routes.Add(myroute3);
[code]...
View 12 Replies
Nov 22, 2010
I have a site (ex. test.com) which I am using MVC. I have created areas for my site, where each area represents a state. What I would like to do is specify some place in the web.config to when I deploy, I set a value and then the default route when I go to test.com would auto route to: test.com/california or test.com/oregon based on that value.
View 2 Replies
Feb 11, 2011
Can I make the default MVC Route to be just an area root? Basically on Global.asax I have the following:
[Code]....
But I ended up in /Home/Index and not in the area. Does this make sense?
View 7 Replies
Feb 17, 2010
I have an application that I run in several places (demo, production, local, etc.) that all use different virtual directories for the placement of the MVC application.
I use StructureMap in this application, so I am overriding the ControllerFactory to use StructureMap to build controllers (when the passed controller instance is not null).
My problem is that the controller instance being passed to the controller factory IS null, which is fine if said route didn't exist, but it does... specifically, it should be my DEFAULT ROOT route.
Basically if I host the app at [URL], everything works fine except when I have a '/' on the end of the URL (meaning,[URL]... the latter works fine, while the former gives me the error). It looks like when that slash is there, the routing engine is deciding that it should be looking for a controller named MvcController, which doesn't exist, and which then passes the null controller instance to the ControllerFactory, resulting in the following error:
The controller for path '/Mvc/' could not be found or it does not implement IController.
My Default route is the standard default route. Removing all other routes has no effect. My default controller is HomeController.
View 3 Replies
Feb 1, 2011
Global.asax route values
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional, filterDate = DateTime.Now.AddDays(-1), filterLevel = "INFO" } // Parameter defaults
);
Here's my actionlink
@Html.ActionLink(item.MachineName, "Machine", new { id = item.MachineName, filterLevel = "hello" }, null)
When the filterlevel is specified in the actionlink, it generates a url like this: [URL] Which is the same page as I am currently on. If I change the actionlink to use a property other than one that has a default value in the route table (yes, if I use filterDate it messes up too), it generates a link like this:..............
View 4 Replies
May 30, 2010
I use in my application 2 areas: Website and Admin. I will put all controllers and views in these areas, not in root application. So I would like to have default route 'Website/Mycontroller/Myaction', not 'Mycontroller/Myaction'. I have changed Global.asax.cs:
[Code]....
to:
[Code]....
but now my application doesn't work when I open website http://xxxxxx.pl.
View 9 Replies
Feb 15, 2011
I'd like to inherit all my controllers from a custom base class that I write myself. I can change the line every time I add a new controller, but it would be nicer if I could somewhere specify the default value that gets set there. That way I wouldn't need to worry about forgetting this, and other people who get added to the project later on would have an easier time.
View 3 Replies
Mar 13, 2011
I tried to mix asp.net 4 webfrom and ASp.Net MVC 3. I add required lines in webconfig, but I've issues implementing route in global.asax
Currently I use several routes for webfroms. routs template are like below
routes.MapPageRoute("Node", _
"article/sport/{nID}/", _
"~/article/articleview.aspx")
I encounter error, when I add below lines to global.asax
routes.MapRoute( _
"Defaultss", _
"{controller}/{action}/{id}", _
New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
)
I want to know how could I mix ASp.Net MVC routes with webforms routes.
View 3 Replies
Mar 9, 2010
when i run the app i got this error
A route named 'Admin_default' is already in the route collection. Route names must be unique.
Parameter name: name
this is my AdminAreaRegistration
[Code]....
View 2 Replies
Sep 24, 2010
I have a url that I want to map routing to:
[URL]
where tabvalue is one of: "personal", "professional", "values" or nothing.
I want to map it to a route like:
Member/Edit/{tab}
But my problem is - I don't know how to specify such constraints. I'm trying this regex:
^[personal|professional|values]{0,1}$
but it only works when I use url
[URL]
[URL]
and doesn't work for
[URL]
how to specify the correct constraint?
P.S. I'm not using MVC, just asp.net WebForms
View 6 Replies
Dec 6, 2010
i want to make some questions about asp.net MVC,actually,i am not familiar with web developing.
But,i am assigned for web part.we are using like this.first,we create get set
properties for person data
public class Person
{
public int personID {get;set;}
public string personName {get;set;}
public string nric {get;set;}
}
and then after login,we put data in that class and we use RedirectToAction method like this,
return RedirectToAction("profile","person",new { personID = Person.personID});
it's working normally,but,parameter are shown at URL,how i hide them and also can i hide action name?
View 2 Replies
May 18, 2010
I have created a custom validation attribute for a class. The validation is actually against one property of the class, but since it needs to be compared to another property of the class at runtime, I had to pull in everything from the input form, perform the validation and output the errors. This being the case, I manually added a ModelError to ModelState if the ModelStats.IsValid returned false. I have another thread that goes into this, as I still haven't been able to make the client-side validation work for the custom validation (built-in validation runs client-side without a problem).
Here's the issue: I want to use the Post/Redirect/Get pattern to avoid issues where users refresh their page and cause another post of the form data. If I complete my Controller action and return a View after assigning an error with ModelState.AddModelError, I get the user feedback with the red input field and error message shown. However, just returning a View like this makes you vulnerable to the repeated posts issue. I want to use RedirectToAction to perform a get and avoid this problem, but when I do that I no longer have the ModelState error feedback on my rendered View. Here're the calls I'm making:
[Code]....
I'd like to be able to redirect to a get action and retain the ModelState.
View 2 Replies
Mar 14, 2011
Was looking at asp.net mvc complex routing for tree path as an example of how to define a custom route handler for my MVC app. Essentially, I want to give the end user ultimate flexibility in defining the URL for any given page, so I provide them with a field in the interface to specify their own custom URL.
My custom route handler is basically a wild-card handler. It will do a lookup and if it finds a match, map it accordingly. However, if no match is found, I want it to fall back and find the next rule that matches in the global.asax. Is that possible? Or do I essentially need to code the mappings that used to exist in my global.asax into my custom route handler?
View 2 Replies
Nov 15, 2010
I want to pass a int value using RedirectToAction() method .
Here i have a Action method Index() which takes 1 parameter id in most of the cases this id cannot be null.
When i submit the form using Action method Edit(), i want to come again on Index page,so i am using method RedirectToAction("Index")
but here with Action Name i want to pass the id also. How can i do it?
View 3 Replies
Oct 2, 2010
I wish to do something like this:
return RedirectToAction<SomeController>(c => Index(someparameter));
How to do this ?
View 2 Replies
Jan 27, 2010
I've a class that hold all the necessary properties. I want to pass the instance of that class in RedirectToAction. Right now, I can pass the instance but the action to which it redirect, doesn't receive that same instance. The target action has new instance of class.
eg.
AbcFilter a = new AbcFilter();
a.ABCname="abc";
RedirectToAction("AbcAction",a);
Public ActionResult AbcAction(AbcFilter a)
{// this method receives the "a" as new instance, but not the same that I pass in RedirectToAction
}
View 3 Replies
May 18, 2010
I've been using MVC since the previews of 1.0 and I think I know what I'm doing, but for the life of me I can not figure out why sometimes when I use RedirectToAction it crashes saying there is no route available. Consider this in MVC 2.0:
I'm registering on my site and I first hit the SiteController, which does its magic then I am to be redirected to my new dashboard, controlled by the... DashboardController. I never make it there. I specify the action and the controller in the redirect call, but it still crashes and burns. The only thing I can possible think of is because the DashboardController is its own area, but that still doesn't help me because by my understanding it should still work regardless.
View 1 Replies
Oct 13, 2010
I have Action method in a controller which uses RedirectToAction(actionName, routeValues[])I want to write the unit test for action method to check the following - 1. action name2. ViewData after executing the RedirectToAction.
View 1 Replies
Apr 12, 2010
I've been trying to get the strongly typed version of RedirectToAction from the MVC Futures project to work, but I've been getting no where. Below are the steps I've followed, and the errors I've encountered.
I created a new MVC2 app and changed the About action on the HomeController to redirect to the Index page.
Return RedirectToAction("Index")
However, I wanted to use the strongly typed extensions, so I downloaded the MVC Futures from CodePlex and added a reference to Microsoft.Web.Mvc to my project.
I addded the following "import" statement to the top of HomeContoller.vb
Imports Microsoft.Web.Mvc
I commented out the above RedirectToAction and added the following line:
Return RedirectToAction(Of HomeController)(Function(c) c.Index())
So far, so good. However, I noticed if I uncomment out the first (non Generic) RedirectToAction, it was now causing the following compile error:
Error 1 Overload resolution failed because no accessible 'RedirectToAction' can be called with these arguments:
Extension method 'Public Function RedirectToAction(Of TController)(action As System.Linq.Expressions.Expression(Of System.Action(Of TController))) As System.Web.Mvc.RedirectToRouteResult' defined in 'Microsoft.Web.Mvc.ControllerExtensions': Data type(s) of the type parameter(s) cannot be >inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
Extension method 'Public Function RedirectToAction(action As System.Linq.Expressions.Expression(Of System.Action(Of HomeController))) As System.Web.Mvc.RedirectToRouteResult' defined in 'Microsoft.Web.Mvc.ControllerExtensions': Value of type 'String' cannot be converted to 'System.Linq.Expressions.Expression(Of System.Action(Of mvc2test1.HomeController))'.
Even though intelli-sense was showing 8 overloads (the original 6 non-generic overloads, plus the 2 new generic overloads from the Futures assembly), it seems when trying to complie the code, the compiler would only 'find' the 2 non-gneneric extension methods from the Futures assessmbly.
I thought this might be an issue that I was using conflicting versions of the MVC2 assembly, and the futures assembly, so I added MvcDiaganotics.aspx from the Futures download to my project and everytyhing looked correct:
ASP.NET MVC Assembly Information (System.Web.Mvc.dll)
Assembly version: ASP.NET MVC 2 RTM (2.0.50217.0)
Full name: System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Code base: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Web.Mvc/2.0.0.0__31bf3856ad364e35/System.Web.Mvc.dll
Deployment: GAC-deployed
ASP.NET MVC Futures Assembly Information (Microsoft.Web.Mvc.dll)
Assembly version: ASP.NET MVC 2 RTM Futures (2.0.50217.0)
Full name: Microsoft.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null
Code base: file:///xxxx/bin/Microsoft.Web.Mvc.DLL
Deployment: bin-deployed
This is driving me crazy! Becuase I thought this might be some VB issue, I created a new MVC2 project using C# and tried the same as above.
I added the following "using" statement to the top of HomeController.cs
using Microsoft.Web.Mvc;
This time, in the About action method, I could only manage to call the non-generic RedirectToAction by typing the full commmand as follows:
return Microsoft.Web.Mvc.ControllerExtensions.RedirectToAction<HomeController>(this, c => c.Index());
Even though I had a "using" statement at the top of the class, if I tried to call the non-generic RedirectToAction as follows:
return RedirectToAction<HomeController>(c => c.Index());
I would get the following compile error:
Error 1 The non-generic method 'System.Web.Mvc.Controller.RedirectToAction(string)' cannot be used with type arguments
What gives? It's not like I'm trying to do anything out of the ordinary.It's a simple vanilla MVC2 project with only a reference to the Futures assembly.
I'm hoping that I've missed out something obvious, but I've been scratching my head for too long, so I figured I'd seek some assisstance.
If anyone's managed to get this simple scenario working (in VB and/or C#)
View 1 Replies
Jun 6, 2010
i built an MVC application, in one of my views, i'm activating an ActionResult using JQuery.$post in this ActionResult i'm using RdirectToAction to another ActionResult, this ActionResult is really reached and executed, but when i'm trying to use another RdirectToAction from here, its not happened.
View 6 Replies
Mar 4, 2011
I am new to MVC2 and have hit a wall. When I use an action link to jump back to a previous page that I have already been on, my controller is not called but the page is rendered correctly. Is this some sort of caching that I am not aware of? This also happens with a RedirectToAction call from another Controller. rfm is the Model...
return RedirectToAction("Search", rfm);
Here is the actionlink...
<%: Html.ActionLink("Search", "Search", "Reference")%>
View 3 Replies