在 .Net MVC 中,实现多重编辑功能(允许同时编辑列表中的多个字段)的惯用方法是什么?
我正在尝试创建一个 MVC 表单,该表单允许用户同时编辑多个记录,并将更改作为批量更新提交到我的数据。下面的代码向您展示了我如何显示要编辑的数据。这应该是开箱即用的吗?用户是否应该能够单击“提交”并使我的“更新”消息收到包含所有适当更改的模型?
如果没有,那么在 .Net MVC 中实现这样的事情的惯用方法是什么?
@using (Html.BeginForm( "Update", "SomeController", Model)) {
<div>
<fieldset>
<ul id="categoryEditor" style="list-style-type: none">
@for (int i = 0; i < Model.AList.Count(); i++) {
@Html.HiddenFor( model => model.AList[i].ID )
@(Model.AList[i].Name)
@Html.EditorFor( model => model.AList[i].Category )
}
</ul>
<p>
<input type="submit" value="Update" />
</p>
</fieldset>
</div>
}
I'm trying to create an MVC form which will allow a user to edit multiple records at the same time, and submit the changes as a batch update to my data. The code below shows you how I'm displaying the data to be edited. Is this supposed to work out of the box? Should the user be able to click "Submit" and have my "Update" message receive a model containing all of the appropriate changes?
If not, then what's the idiomatic way to implement something like this in .Net MVC?
@using (Html.BeginForm( "Update", "SomeController", Model)) {
<div>
<fieldset>
<ul id="categoryEditor" style="list-style-type: none">
@for (int i = 0; i < Model.AList.Count(); i++) {
@Html.HiddenFor( model => model.AList[i].ID )
@(Model.AList[i].Name)
@Html.EditorFor( model => model.AList[i].Category )
}
</ul>
<p>
<input type="submit" value="Update" />
</p>
</fieldset>
</div>
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论