【发布时间】:2018-11-26 09:20:51
【问题描述】:
我有一个 MVC 表单,我想在其中显示一些不可编辑的值。
<form asp-action="AuthorizeTransaction" method="post">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="To"></label>
<input asp-for="To" class="form-control" />
<label asp-for="Amount"></label>
<input asp-for="Amount" class="form-control" />
<label asp-for="Currency"></label>
<input asp-for="Currency" class="form-control" />
<label asp-for="Description"></label>
<input asp-for="Description" class="form-control" />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
我知道我可能可以将输入设为只读,但我想知道是否有一种方法可以在不使用文本框的情况下显示表单值并且仍然发布值。我想做这样的事情:
<label asp-for="Amount"></label>
<display asp-for"Amount"></display>
<input type="hidden" asp-for="Amount" class="form-control" />
【问题讨论】:
-
<display asp-for"Amount"></display>在 .NET Core 中是未知的。另请注意,@Html.DisplayFor()helper 只显示值,您需要隐藏字段来回发,以便您可以尝试同时呈现值和隐藏字段的自定义标签助手。
标签: c# html model-view-controller .net-core