iuliu.net
iuliu.net

Reputation: 7145

Submit button posts to wrong action and uses action route as ReturnUrl

I'm on /Home/Index. The HTML of the button in question looks like this:

<form action="/Account/ConfirmMail" class="form-inline" method="post" style="display: inline-block" title="Codul de confirmare primit pe e-mail">
    <input class="form-control form-input" data-val="true" data-val-required="N-ai băgat nimic.. De ce apeși butoane așa aiurea?" id="ConfirmationCode" name="ConfirmationCode" placeholder="Cod" style="width: 70px" type="text" value="" />
    <input type="submit" class="btn btn-info" title="Trimite" value="Poftim" />
</form>

When I click the submit button, the link goes to a 404 page at http://localhost:62500/Account/Login?ReturnUrl=%2FAccount%2FConfirmMail

This is of course not my expected nor intended outcome.

Additional info:

Razor code that generated that:

@model LigaDePredictii.Models.ConfirmationCodeViewModel
@using (Html.BeginForm("ConfirmMail", "Account", FormMethod.Post, new { @class = "form-inline", title="Codul de confirmare primit pe e-mail", style="display: inline-block" }))
{
    @Html.TextBoxFor(x => x.ConfirmationCode, new { @class = "form-control form-input", placeholder = "Cod", style = "width: 70px" })
    <input type="submit" class="btn btn-info" title="Trimite" value="Poftim" />
}

Which gets rendered in:

<div class="alert alert-danger alert-dismissible" role="alert">
    <span class="glyphicon glyphicon-log-in" aria-hidden="true"></span>
    <strong>Nu-i bun codul!</strong> Asigură-te că e cel primit în mail.
    @Html.Partial("ConfirmCodeAndSubmit")
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span></button>    
</div>

Upvotes: 1

Views: 569

Answers (2)

Sergio S
Sergio S

Reputation: 192

I think you want something like the following assuming you have Action set up correctly:

<form action="@Url.Action("ConfirmEmail", "Account")" class="form-inline" method="post" style="display: inline-block" title="Codul de confirmare primit pe e-mail">
    <input class="form-control form-input" data-val="true" data-val-required="N-ai băgat nimic.. De ce apeși butoane așa aiurea?" id="ConfirmationCode" name="ConfirmationCode" placeholder="Cod" style="width: 70px" type="text" value="" />
    <input type="submit" class="btn btn-info" title="Trimite" value="Poftim" />
</form>

Upvotes: 1

JoshBerke
JoshBerke

Reputation: 67088

It's redirecting because your trying to access a resource which requires authentication/authorization and your not authenticated. If you use fiddler you will see it posting to the right action, but the server is sending a redirect to the login page.

You could add this to your web.config file:

 <location path="Account">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>

Which allows unauthorized users to access anything in your account controller

Upvotes: 1

Related Questions