3

Redirecting a method in a class to an action causes a controller

 2 years ago
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

advertisements

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

Here is my problem : I want to assign an Event on an UIButton. I use this method : - (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents like this : [newsButton addTarget:self action:@selector(myEvent2) forCo

Keeps the value of a variable from one method to another via a view in the Codeigniter controller class

I'm new in php. I'm doing a project on online bus ticket system. In a part of the system i want to update a table of database. At first i want to display all the rows of the table which i have done in index method. When a row is selected it's attribu

Generic view redirection based on the Django class

Consider the following: urls.py: urlpatterns = patterns('', ('^test/$', ClassView.as_view()), ) views.py: class ClassView(View): def get(self, request): return HttpResponse("test") def post(self, request): # do something return redirect(ClassVie

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;

I am new to Play Framework, and attempting to build a Todo-list from this manual. When I try to run the application I get the error: Compilation Error error: method render in class index cannot be applied to given types; My code is (the relevant part

Automatically decorate each method in a class

I would like to add some logic before and after every time I'm using a method (doesn't really matter if is private, protected or public) in a class. For example: class Service { function test1() { Log:start(__METHOD__); someLogicInThere(); .... Log:e

How do I declare that my method requires a class?

When Method require any string we write that void method(string str) { str="OK"; } I have a method that require any class. Little part of my method: Void Post() { responsefromserver = new JavaScriptSerializer.Deserialize<T>(sr.ReadToEnd())

Set the method in the class constructor to perl

I am reading code snippets like below: sub new { my $pkg = shift; my $args = shift; my @keys = keys %$args; my $self = bless \%{$args}, $pkg; $self->{'__properties'} = \@keys; my $class = ref($self); foreach my $meth (@keys) { if (! $self->can($meth

What is the call format of a method of another class?

If I would like to call a method from another class to input it into the current class that I am working on, how do I format it to call the method? How is the code written to call for the method. Currently I have my floats array that is a method? wri

JQuery different methods to add classes

I have seen a few different methods for adding classes to dynamically created elements using JQuery. I'm most familiar with $("<div />").addClass("class1 class2"); however I have seen a lot of $("<div />", { class

JUnit Mockito mocks method in another class Error

I use Netbeans 8.1 , Junit and Mockito to write unit test for my project. Here is some pieces of my code To be tested function: public Map<String, String> getAllUsers() { if (allUsers == null) { if (session.checkACL2("DonateBookPrivilegeLevel&q

Provide a list of methods in a class to use outside of it

How can I provide a list of methods in a class for use outside of it? What I'm looking for When I create an object from a class extending a higher class, I want to get a list of specific methods, some "meta data" of them, and to able to call the

Ruby: Add a method to the class of an input parameter

I'm just exploring ruby and was wondering about the theoretical possibility of adding a method to the class of an object. For example, define a method that takes in a parameter and would add a method to the class of that parameter (not just to the pa

Can I simply include a particular member method of a class?

I have a cpp file which only uses only one method of a large class. To do that I usually include the large class declaration header file. Can I just include a particular member method of a class?Short answer: No. When you include a header, you includ

Executing methods of another class in Java

I've been trying out Java with Eclipse and I'm having trouble running methods from another class. I have read other posts about this subject, but I still couldn't get it to work. Here is my code: (All files are in the same Java project) (Code from on

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK