2009-10-11 67 views
0

查看Ajax.Actionlink,如何將表單數據到控制器的動作

<%= 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> 

<% } %> 

控制器

[AcceptVerbs(HttpVerbs.Post)] 
    public ActionResult Create(Customer info) 
    { 
     //INFO IS NULL??? 
     //WHAT IS THE PROBLEM? 
    } 

回答

2

您無法通過模型對象。該參數需要路由值,例如ID。

,如果你在Ajax.ActionLink("Create", "Create", new { id=23 }, ....

通過它將創建/create/23

相關問題