【发布时间】:2022-01-23 08:38:45
【问题描述】:
我正在开发一项功能,该功能允许代理商检查和修改客户购买的库存。
基本上,它是引导模式内的更新表单,它位于另一个局部视图下的局部视图中。
起初,我尝试使用标签助手将我的视图模型与模态框内的表单绑定。比如:
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Update Inventory</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form id="UpdateForm" asp-controller="Home" asp-action="UpdateD" data-ajax-method="post" data-ajax="true" data-ajax-success="InsertSuccess">
<div class="modal-body">
<div class="mb-3 row">
<label asp-for="FieldExample" class="col-sm-2 col-form-label">FieldExample</label>
<div class="col-sm-10">
<input asp-for="FieldExample" class="form-control">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">UpdateBtn</button>
</div>
</form>
</div>
</div>
我检查了表单标签是否正确关闭,数据字段是否有效。
但表单结果显示没有我的字段,立即关闭,如下所示:
<form id="UpdateForm" data-ajax-method="post" data-ajax="true" data-ajax-success="InsertSuccess" action="/Home/UpdateD" method="post"></form>
<div class="modal-body">
<div class="mb-3 row">
<label class="col-sm-2 col-form-label" for="PLAN_TYPE">FieldExample</label>
<div class="col-sm-10">
<input class="form-control" type="text" id="FieldExample" name="FieldExample" value="test">
</div>
</div>
(...other fields)
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">UpdateBtn</button>
</div>
<input name="__RequestVerificationToken" type="hidden" value="...">
</div>
由于某种原因,表单不包含我的数据字段,我不知道是什么原因造成的。
即使我尝试使用带有测试字段的简单表单标签制作表单,表单仍然格式错误(内部没有字段)。
如果有人提出建议,我将不胜感激(对不起我的语言)
【问题讨论】:
-
你总是可以用老式(但可靠)手动
action=""属性替换asp-标签助手属性使用IUrlHelper。 -
检查控制台了解错误详情
标签: asp.net-core-mvc .net-6.0 tag-helpers