Redirecting a method in a class to an action causes a controller
source link: https://www.codesd.com/item/redirecting-a-method-in-a-class-to-an-action-causes-a-controller.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Redirecting a method in a class to an action causes a controller
I have a mvc application and when a user is authenticated, a method is called from a class to determine the type of user.
I will like to do a redirect to an action result in a controller from a method in a class.
How do i redirect from a method in a class to an action result in a controller?
There might be a good reason for why you want to do it this way, but I want to suggest an alternative for you. I would suggest that you redirect to an action based on the result from a method in a class, rather than doing the redirection in the method itself.
Pseudo-code:
public ActionResult Index()
{
var tmp = new YourClass();
if(tmp.UserType().Equals("Admin")
{
return RedirectToAction("Admin", "Home");
}
if(tmp.UserType().Equals("User"))
{
return RedirectToAction("User","Home");
}
}
Related Articles
Objective-C: Calling a method from another class in addTarget: action: forControlEvents
Keeps the value of a variable from one method to another via a view in the Codeigniter controller class
Generic view redirection based on the Django class
Play Framework 2.2.1 - Compilation Error: & ldquo; The rendering of the method in the class index can not be applied to the given types; & Rdquo;
Automatically decorate each method in a class
How do I declare that my method requires a class?
Set the method in the class constructor to perl
What is the call format of a method of another class?
JQuery different methods to add classes
JUnit Mockito mocks method in another class Error
Provide a list of methods in a class to use outside of it
Ruby: Add a method to the class of an input parameter
Can I simply include a particular member method of a class?
Executing methods of another class in Java
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK