MVC在编辑后将旧文本值传递给控制器

时间:2018-10-10 11:10:30

标签: c# .net model-view-controller

我有一个文本字段,其中的文本是从viewmodel加载的,然后我想更改文本并将其发送到我的控制器。但是在我编辑了文本之后,控制器从我的文本字段中收到了旧的文本值。

我的观点:

    @model Football_Insider.ViewModels.ArticleViewModel

    @{
        ViewBag.Title = "EditArticle";
    }

<section id="breadcrumb">
    <div class="container">
        <ol class="breadcrumb">
            <li class="active"></li>
        </ol>
    </div>
</section>

    @using (@Html.BeginForm("EditArticle", "Article", FormMethod.Post, new { 
    enctype = "multipart/form-data" }))
    {
    <div class="form-group">
        @Html.LabelFor(model => model.Article.Title, htmlAttributes: new { @class = "control-label col-md-12" })
        <div class="col-md-12">
            @Html.EditorFor(model => model.Article.Title, new { htmlAttributes = new { @class = "form-control col-md-12" } })
            @Html.ValidationMessageFor(model => model.Article.Title, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Article.Content, htmlAttributes: new { @class = "control-label col-md-12" })
        <div class="col-md-12">
            @Html.TextAreaFor(model => model.Article.Content, new { @class = "form-control col-md-12", @rows = 20, @cols = 50 })
            @Html.ValidationMessageFor(model => model.Article.Content, "", new { @class = "text-danger" })
        </div>
    </div>
    @Html.Hidden("articleId", Model.Article.ArticleId)
    @Html.Hidden("title", Model.Article.Title)
    @Html.Hidden("content", Model.Article.Content)

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Volgende" class="btn btn-primary" />
        </div>
    </div>

1 个答案:

答案 0 :(得分:1)

您需要删除@Html.Hidden("content", Model.Article.Content) 因为它会覆盖您的文本区域值