mvc partial view post

佐手、 提交于 2019-12-05 10:27:37

You need to surround each set of fields that you want submitted with a separate form tag. You can have more than one form tag per page. In fact, you might want each partial view to have its own form tag that submits to a different controller action.

Put the partial views wherever makes most sense. The file location has nothing to do with how the form is submitted back from the browser.

You can post to different controllers like this. One posts to the Branch controller and one posts to the Company controller.

<% using (Html.BeginForm("RemoveBranch", "Branch", FormMethod.Post, new { @class = "branchform" }))
   {

       Html.RenderPartial("~/Views/Branch/BranchView.ascx");    

}%>

<% using (Html.BeginForm("RemoveCompany", "Company", FormMethod.Post, new { @class = "companyform" }))
   {

       Html.RenderPartial("~/Views/Company/CompanyView.ascx");    

}%>

In each view or partial view, all you need is a submit button:

<input type="submit" value="Delete" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!