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