Multiple actions with same action name

mohsinali1317

I have multiple action in my controller like this

public ActionResult Verify(String email, String name ){
        ViewBag.email = email;
        ViewBag.name = name;
        return View();
}

[HttpGet]
public ActionResult Verify(String uId){
        User user = TippNett.Core.User.Get(uId);
        user.Active = true;
        user.Save();
        Auth.Authenticate(user, false);
        return RedirectToAction("Index", "Home");
}

The first action is when the user registers to show him the registration message that please verify the email and I am calling it like this

return RedirectToAction("Verify", "Account", new { email = email, name = user.FirstName});

The second action is being called when the user clicks on the verification link. The issue is this that the below function is being called always. Even when I pass email and name as parameters as well.

Can anyone explain why this happens and possibly a work around this?

Tushar

You can use:

[ActionName("MyOverloadedName")]

or

method overloading based on attribute:

[RequireRequestValue("someInt")]
public ActionResult MyMethod(int someInt) { /* ... */ }

[RequireRequestValue("someString")]
public ActionResult MyMethod(string someString) { /* ... */ }

public class RequireRequestValueAttribute : ActionMethodSelectorAttribute {
    public RequireRequestValueAttribute(string valueName) {
        ValueName = valueName;
    }
    public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) {
        return (controllerContext.HttpContext.Request[ValueName] != null);
    }
    public string ValueName { get; private set; }
}

But, you'll have to use a different action name for the same http method as you can only have the same method when using different http methods. Like:

[HttpPost]
public ActionResult Verify(String email, String name ){
      }

[HttpGet]
public ActionResult Verify(String uId){
        User user = TippNett.Core.User.Get(uId);
        user.Active = true;
        user.Save();
        Auth.Authenticate(user, false);
        return RedirectToAction("Index", "Home");
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Handle Multiple action with same name in MVC

From Dev

Can you define multiple actions with the same name in Rails?

From Dev

Android receivers - Same name and action of receiver in multiple apps

From Dev

Multiple DropDownList but same action

From Dev

Controller with multiple actions - wrong action called

From Dev

Action to spawn multiple further actions in Gatling scenario

From Dev

Multiple parameters by the same name

From Dev

Multiple functions with the same name

From Dev

Multiple divs with same name

From Dev

Multiple inputs with same name

From Java

Asp.Net Core - multiple action methods with the same name and different parameters

From Dev

Can multiple actions serve the same view?

From Dev

RESTful APIs when multiple actions on the same URI

From Dev

Specific and same actions when catching multiple exceptions

From Dev

How to dispatch multiple actions from same component?

From Dev

Getting multiple buttons for the same action

From Dev

Ho to access the Action from WebApiController with many actions and same parameters

From Dev

Invoking Same Name Controller Action for Mobile Devices

From Dev

Is it mandatory to name view and action mehod same in mvc?

From Dev

Invoking Same Name Controller Action for Mobile Devices

From Dev

Action name in MVC same as corresponding http verb

From Dev

Multiple EJB beans with same name

From Dev

Multiple Inheritance: same variable name

From Dev

Multiple external packages with same name

From Dev

Laravel - multiple controllers with same name

From Dev

Behave, multiple steps with same name

From Dev

Saving multiple files with same name

From Dev

Submitting multiple inputs with same name

From Dev

Parse multiple headers with same name

Related Related

  1. 1

    Handle Multiple action with same name in MVC

  2. 2

    Can you define multiple actions with the same name in Rails?

  3. 3

    Android receivers - Same name and action of receiver in multiple apps

  4. 4

    Multiple DropDownList but same action

  5. 5

    Controller with multiple actions - wrong action called

  6. 6

    Action to spawn multiple further actions in Gatling scenario

  7. 7

    Multiple parameters by the same name

  8. 8

    Multiple functions with the same name

  9. 9

    Multiple divs with same name

  10. 10

    Multiple inputs with same name

  11. 11

    Asp.Net Core - multiple action methods with the same name and different parameters

  12. 12

    Can multiple actions serve the same view?

  13. 13

    RESTful APIs when multiple actions on the same URI

  14. 14

    Specific and same actions when catching multiple exceptions

  15. 15

    How to dispatch multiple actions from same component?

  16. 16

    Getting multiple buttons for the same action

  17. 17

    Ho to access the Action from WebApiController with many actions and same parameters

  18. 18

    Invoking Same Name Controller Action for Mobile Devices

  19. 19

    Is it mandatory to name view and action mehod same in mvc?

  20. 20

    Invoking Same Name Controller Action for Mobile Devices

  21. 21

    Action name in MVC same as corresponding http verb

  22. 22

    Multiple EJB beans with same name

  23. 23

    Multiple Inheritance: same variable name

  24. 24

    Multiple external packages with same name

  25. 25

    Laravel - multiple controllers with same name

  26. 26

    Behave, multiple steps with same name

  27. 27

    Saving multiple files with same name

  28. 28

    Submitting multiple inputs with same name

  29. 29

    Parse multiple headers with same name

HotTag

Archive