How do I create a strongly typed BeginForm?

前端 未结 2 1694
长发绾君心
长发绾君心 2021-01-20 19:59

I\'ve seen a few examples of people using this syntax for HTML.BeginForm:

(Html.BeginForm(action => action.ActionName(id)))

2条回答
  •  情话喂你
    2021-01-20 20:28

    Here is an example, in your .aspx view:

    "UserController" being your controller.
    "Save()" being your action method in the controller.

    <%
    using (Html.BeginForm(x => x.Save(null, null, Model.User.ID, null, null), FormMethod.Post, new { id = "formUser" })) {
    %>
       <%= Html.AntiForgeryToken() %>
       <%: Html.ValidationSummary(true) %>
       ...
    <% } %>
    

    Hope that helps.

提交回复
热议问题