mvc部分视图帖子
我有一个公司对象,其中包含分支对象列表,
我的公司视图(驻留在公司目录中)有一个强类型分支列表视图(驻留在分支目录中),
分支视图中的每个分支都有一个删除按钮我想将其发布到分支控制器中的删除操作。
目前调用的删除操作是公司控制器中的操作
(公司和分支机构都有删除操作)
我相信我理解它这样做的原因,但是在这种情况下最佳实践是什么...... .
- 分支列表部分视图应该驻留在公司目录还是分支目录中?
- 删除分支操作应该驻留在公司还是分支控制器中?
我认为分支列表应该位于分支目录中并调用分支控制器,但是当部分视图加载到公司详细信息视图中时,如何让它执行此操作?
希望这是有道理的,
谢谢,
马克
<% foreach (var item in Model) { %>
<tr>
<td>
<form action="Edit" method="get">
<input type="submit" value="Edit" id="Submit1" />
<input type="hidden" name="id" value="<%= item.Id %>" />
</form>
|
<form action="Branch" method="get">
<input type="submit" value="Details" id="Submit2" />
<input type="hidden" name="id" value="<%= item.Id %>" />
</form>
|
<form action="BranchDelete" method="post">
<input type="submit" value="BranchDelete" id="Submit1" />
<input type="hidden" name="id" value="<%= item.Id %>" />
</form>
I have a company object which has a list of branch objects,
my company view(residing in the company directory) has a strongly typed branch list view (residing in the branch directory)in it,
each branch in the branch view has a delete button which I want to post to a delete action in the branch controller.
at present the invoked delete action is the one in the company controller
(there is a delete action in both company and branch)
I believe I understand the reason it is doing what it is, however what is the best practice in this situation....
- should the branch list partial view reside in the company or branch directory?
- should the delete branch action reside in the company or the branch controller?
I would think the branch list should be in the branch directory and call the branch controller, but how do I get it to do this when the partial view is loaded into the company details View?
Hope that made sense,
Thanks,
Mark
<% foreach (var item in Model) { %>
<tr>
<td>
<form action="Edit" method="get">
<input type="submit" value="Edit" id="Submit1" />
<input type="hidden" name="id" value="<%= item.Id %>" />
</form>
|
<form action="Branch" method="get">
<input type="submit" value="Details" id="Submit2" />
<input type="hidden" name="id" value="<%= item.Id %>" />
</form>
|
<form action="BranchDelete" method="post">
<input type="submit" value="BranchDelete" id="Submit1" />
<input type="hidden" name="id" value="<%= item.Id %>" />
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要用单独的表单标签包围要提交的每组字段。每页可以有多个表单标签。事实上,您可能希望每个分部视图都有自己的表单标签,提交到不同的控制器操作。
将部分视图放在最有意义的地方。文件位置与表单从浏览器提交回来的方式无关。
您可以像这样发布到不同的控制器。一名担任分公司财务总监,一名担任公司财务总监。
在每个视图或部分视图中,您只需要一个提交按钮:
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.
In each view or partial view, all you need is a submit button: