为什么[HttpPost]只接收';编辑器适用于';

本文关键字:编辑器 适用于 HttpPost 为什么 | 更新日期: 2023-09-27 18:27:57

我使用MVC Razor,当我试图编辑某个东西时,我会通过ViewModel传递它,它包含所有必要的信息,我已经测试过了。

这是我的看法:

<div class="editor-label">
        @Html.LabelFor(model => model.CollectionId)
    </div>
    <div class="editor-field">
        @Html.DisplayFor(model => model.CollectionId)
    </div>
    <div class="editor-label">
        @Html.LabelFor(model => model.BrandName)
    </div>
    <div class="editor-field">
        @Html.DisplayFor(model => model.BrandName)
    </div>
    <div class="editor-label">
        @Html.LabelFor(model => model.Season)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Season)
        @Html.ValidationMessageFor(model => model.Season)
    </div>

正如你所看到的,我只在他们可以更改的信息上使用@Html.EditorFor,因为这就是我想要更改的全部内容。但我觉得有必要向他们展示其他信息,让他们确切地知道自己在编辑什么。

我的问题是,我如何在不允许他们编辑信息的情况下,实现相当于@Html.EditorFor传递信息的效果?

为什么[HttpPost]只接收';编辑器适用于';

您必须使用Html.HiddFor将它们的值传递回控制器。

例如

<div class="editor-field">
    @Html.DisplayFor(model => model.CollectionId)
    @Html.HiddenFor(model => model.CollectionId)
</div>