2

I am getting this error.

The current request for action 'Login' on controller type 'AccountController' is ambiguous between the following action methods:  
System.Web.Mvc.ActionResult Login(MVCApp.Models.Account) on type MVCApp.Controllers.AccountController  
System.Web.Mvc.ActionResult SignIn(MVCApp.Models.Account) on type MVCApp.Controllers.AccountController

Here is my Code

<input type="submit" name="Login" value="Login" />
<input type="submit" name="SignIn" value="SignIn" />
public class HttpParamActionAttribute : ActionNameSelectorAttribute
{
    public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
    {
        if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
            return true;

        var request = controllerContext.RequestContext.HttpContext.Request;
        return request[methodInfo.Name] != null;
    }
}

public ActionResult Login()
{
    return View();
}

[HttpPost]
[HttpParamAction]
public ActionResult Login(Account account)
{
    Account createAccount = new Account();

    createAccount.Username = account.Username;
    createAccount.Email = account.Email;
    createAccount.Password = account.Password;

    return View("Login");
}

// GET: /Account/SignUp

public ActionResult SignIn()
{
    return View();
}

[HttpPost]
[HttpParamAction]
public ActionResult SignIn(Account account)
{
    Account createAccount = new Account();

    createAccount.Username = account.Username;
    createAccount.Email = account.Email;
    createAccount.Password = account.Password;

    return View("SignUp");
}
4
  • method name different so i think this should not happen Commented Jun 24, 2014 at 18:40
  • show your view in which you have form Commented Jun 24, 2014 at 18:40
  • Can we see you route config Commented Jun 24, 2014 at 18:45
  • @3dd Here. is my route config public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional } ); } Commented Jun 24, 2014 at 18:54

1 Answer 1

3

So you clicked the SignIn button which is routed to the Login action. The error is caused because HttpParamActionAttribute is returning true for IsValidName for both SignIn and Login actions.

Your HttpParamActionAttribute returns true for IsValidName against the Login action because the Login action matches by name.

Now your other HttpParamActionAttribute on SignIn also returns true because request["SignIn"] is not equal to null.

Change your view to look for an action that is not "LogIn" and also not "SignIn". That way only the action that matches the button name will return true for IsValidName.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.