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?
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.
Comments