Ajax.Actionlink,如何将表单数据传递给控制器​​动作

时间:2009-10-11 02:53:07

标签: asp.net asp.net-mvc

查看

<%= Ajax.ActionLink("Create", "Create", ViewData.Model, new AjaxOptions { HttpMethod = "POST" })%>

<%= Html.ValidationSummary("Create was unsuccessful. Please correct the errors and try again.") %>

<% using (Ajax.BeginForm("Create", "Customer", ViewData.Model, new AjaxOptions { HttpMethod ="POST" }))
   {%>

    <fieldset>
        <legend>Fields</legend>
        <p>
            <label for="Title">Title:</label>
            <%= Html.TextBox("Name")%>
            <%= Html.ValidationMessage("Name", "*")%>
        </p>
        <p>
            <label for="Description">Description:</label>
            <%= Html.TextArea("ContactNo")%>
            <%= Html.ValidationMessage("Name", "*")%>
        </p>           

    </fieldset>

<% } %>

<%= Html.ValidationSummary("Create was unsuccessful. Please correct the errors and try again.") %> <% using (Ajax.BeginForm("Create", "Customer", ViewData.Model, new AjaxOptions { HttpMethod ="POST" })) {%> <fieldset> <legend>Fields</legend> <p> <label for="Title">Title:</label> <%= Html.TextBox("Name")%> <%= Html.ValidationMessage("Name", "*")%> </p> <p> <label for="Description">Description:</label> <%= Html.TextArea("ContactNo")%> <%= Html.ValidationMessage("Name", "*")%> </p> </fieldset> <% } %>

控制器


1 个答案:

答案 0 :(得分:2)

您无法传递模型对象。此参数需要路由值,例如ID。

如果您传入Ajax.ActionLink("Create", "Create", new { id=23 }, ....

它会创建/create/23