Link to home
Start Free TrialLog in
Avatar of ToString1
ToString1

asked on

MVC HTML.Actionlink to route to different controller action

What is the best approach to route the following to a controller action from anywhere with an MVC app?  The following code is everywhere in the app and I need to make it a link so that it routes back to a user details page.   I have two areas in the app  SuperAdmin and TeamAdmin and I want to redirect back to the SuperAdmin edit user page if in  SuperAdmin area and route back to the TeamAdmin area if in TeamAdmin.   I guess I may need to replicate a bit of edit user functionality as they both do different things.

So this needs amending so if clicked on it goes to the users controller "details" action passing the userID

 <%=  Html.Encode(Model.OriginatingUser.FirstName + ", " + Model.OriginatingUser.Surname) %>



SOLUTION
Avatar of ToddBeaulieu
ToddBeaulieu
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ToString1
ToString1

ASKER


I need something this

Html.ActionLink( Html.Encode(Model.User.Username), "RedirectToUser", "UserController",  new {id=Model.User.Id } )%>

So if it is made into a user control it will redirect to the user details page
I'm pobably being thick ... so what is the issue? You can include all those arguments with ActionLink, right?

 User generated image
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm still getting to grips with MVC.

Could you provide a code example please modifying this?    

Html.ActionLink( Html.Encode(Model.User.Username), "RedirectToUser", "UserController",  new {id=Model.User.Id } )%>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
IT actually redirects to

applicationName/RedirectToUser    

It thinks that "RedirectToUser" is a view   - where in my code ive got a redirectToAction called "RedirectToUser"


Wherever I am in the application I want to route it to the Users conroller "edit" method


SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So I guess what I am saying is that I want to implement the following

I have a username   "Doe, Jon"    Clicking on that from wherever it is displayed in any view I want to navigate to    

myApp/Users/Edit/1

As I already know the userID



SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks nmarun

Brilliant

Sorry I was causing confusion