質問

Can you help me interpret this piece of code? What happens after the user clicks Log In?

@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl })) 
{
<fieldset>
    <legend>Log in Form</legend>
    <ol>
        <li>
            @Html.LabelFor(m => m.UserName)
            @Html.TextBoxFor(m => m.UserName)
            @Html.ValidationMessageFor(m => m.UserName)
        </li>
        <li>
            @Html.LabelFor(m => m.Password)
            @Html.PasswordFor(m => m.Password)
            @Html.ValidationMessageFor(m => m.Password)
        </li>            
    </ol>
    <input type="submit" value="Log in" />
</fieldset>   
}

Btw, could not find google documentation on Html.BeginForm at all.

役に立ちましたか?

解決

The form is submitted to the same URL that rendered it.

As specified in the documentation, the overload used is BeginForm(this HtmlHelper helper, object routeValues), so the value of ReturnUrl will be passed as a route value. What happens to that value depends on the application's routes - typically it will be appended to the request URL as a query string parameter.

Try implementing the view and examining the rendered markup.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top