代码之家  ›  专栏  ›  技术社区  ›  johnny 5

值的MVC只读显示

  •  0
  • johnny 5  · 技术社区  · 7 年前

    我有一个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" />
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Anoop Narayan    7 年前

    根据我的理解,您希望将某些值显示为不可编辑。因此,您可以使用readonly之类的属性,也可以使用 @Html.DisplayFor(m=>m、 属性)一个来自mvc的html帮助程序,使某些内容成为只读。它将作为表单中的标签呈现