Use Custom Route With RedirectToAction (asp.net Mvc)

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


Similar Messages:

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

C# - MVC 3 Custom Route Handler - Skip To Next Custom Route Rule?

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

MVC Custom Routing Long Custom Route Not Clicking In Head?

Jun 5, 2010

I have spent several hours today reading up on doing Custom Routing in ASP.NET MVC. I can understand how to do any type of custom route if it expands from or is similar/smaller than the Default Route. However, I am trying figure out how to do a route similar to:

/Language/{LanguageID}/Question/{QuestionID}/

And what I would like, too, is similar to how SO works. Something like:

/Language/{LanguageID}/Arabic/Question/{QuestionID}/Some-Question-Title

Where "Arabic" and "Some-Question-Title" can be almost anything because what really matters is the ID's

A complete url example might be

[URL]

Am I going beyond what can be done with the extended URL past the language ID?

View 1 Replies

How Will You Do This In MVC Custom Route

Jan 22, 2010

www.yoursite.com/image/http://images.google.com.ph/images/nav_logo7.png

What I need to know here is the Controller Action, and the Global.asax routes

View 4 Replies

MVC :: How To Add A Custom Route

Feb 15, 2010

I have added a new route to enable me to have nice seo friendly URLs instead of an id field for some news items I am displaying from a database

My global.asax looks like this

[code]...

The problem I have is that since I have added this extra route all my standard URLS (Home etc) are now displaying the controller and action name after them, for example [URL] is being displayed in the URL for my homepage

The news URLS all look fine they are [URL]

why the Controller/Action is now being displayed on non news URL's and how I can stop this happening, would I use a constraint of some sort on the News route ?

View 3 Replies

MVC Custom Route Fallback?

Jun 5, 2010

I'm wondering if it is possibile to customize routing in a way that all requests are evaluated by a piece of code, redirected to the relevant controller if a match is found or passed to next rout in list if not found.

sample request:
/my coolpage/another one

the code searches and determine that the right controller for this is Page, action is "list" and id is "123" and so redirects

another request:
/products/list/5

code finds no match al passes it back to next route that knows how to handle it...

View 1 Replies

Custom Route With More Than One Parameter In Url (customer - Extra Info)

Jan 31, 2011

I have a multi tenant system and I need to allow administrators to edit the information of other customers. I believe the correct way to do this is to append the customer ID to each request, and update my routes accordingly. How do I make ASP.NET accept and use something like this in the controller (order doesn't mean much to me): [URL] and how would I pass and consume that in my controller? The ASP.NET tutorials skip this... (or I don't know where to search)

View 1 Replies

MVC :: Custom Route Returns 404 When All Optional Parameters Are Null?

Feb 19, 2010

I get a 404 error when I navigate to the following URL using the route below:

http://localhost:53999/properties/

However, all the following are correctly routed to the List action in my controller:

http://localhost:53999/properties/usa/new-york/manhattan/12

http://localhost:53999/properties/usa/new-york/manhattan

http://localhost:53999/properties/usa/new-york

http://localhost:53999/properties/usa [Code]....

In PropertiesController.cs: [Code]....

It looks like it should just go to the default controller/action,

View 5 Replies

C# - Custom MVC Route: Changing Where The Views For A Controller Are Located

Jan 5, 2011

So I have a controller called EmployeeController, and all the Views are in /Employee.

I'd like to create a route so that the EmployeeController will use /Employees and /Employees/Add instead of /Employee and /Employee/Add.

I keep finding articles about how to change the route to go to different actions.

View 3 Replies

MVC :: Webforms Route / Implementing Route In Global.asax

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

MVC :: A Route Named 'Admin_default' Is Already In The Route Collection?

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

Route Constraints And Empty Route?

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

RedirectToAction Usage In Asp.net Mvc

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

MVC :: Using ModelState With RedirectToAction?

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

MVC :: Passing Int Value From RedirectToAction Method?

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

Is There A Strongly Typed RedirectToAction In MVC 2

Oct 2, 2010

I wish to do something like this:

return RedirectToAction<SomeController>(c => Index(someparameter));

How to do this ?

View 2 Replies

MVC :: RedirectToAction And Instance Of Class?7

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

MVC :: RedirectToAction Crashing When A Controller Is Specified?

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

MVC :: Unit Tests For Action Which Uses RedirectToAction?

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

MVC2 And MVC Futures Causing RedirectToAction?

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

MVC :: Nested RedirectToAction After JQuery Post?

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

MVC :: Controller Not Called From Actionlink Or RedirectToAction

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

MVC :: Return RedirectToAction() Passing Object?

Apr 9, 2010

I have the following ActionResult() method:

[Code]....

The method is called once the <form> is submitted. If the validation is good, it moves on to create a new user Once the new user is created, I want to redirect the user to a "ThankYou" page passing along the newly created user (object). The TempData["User"] trick seems to work like a charm! Then inside my ThankYou ActionResult() I do the following:

[Code]....

The problem I have is once the user has been redirected to the "ThankYou" page. If he decides to refresh (F5) his browser, the value in the TempData is lost.

What are my possibilities to overcome this issue?

Instead of passing an entire object to my "ThankYou" page, I initially thought of passing the ID of the newly created user and re-query my database to get the object.

The only problem is that the ID will be seen in the QueryString allowing the user to simply change the ID value and try to find other users...

Is my only other alternative to simply place the user object inside a Session? Is that my only other option?

View 6 Replies

Passing A Controller As A Parameter - Can't Get To RedirectToAction Method

Jun 15, 2010

My method looks like:

public static RedirectToResult(Controller controller, ...)
{
}

when I do:

controller.

I don't see RedirectToAction, how come?

I get RedirectToAction from within the controller's action, but not when I pass the controller as a parameter to another classes method.

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved