本文介绍了Html.DisplayFor不张贴值ASP.NET MVC 3到控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET MVC 3剃须刀,下面是我的表的样子。

I am using ASP.NET MVC 3 with Razor, below is how my Form looks like.

我给用户编辑自己的详细资料,我不希望他能够编辑是EmailAddress的场,所以我用 Html.DisplayFor(M = GT,M。 EmailAddress的)

I am giving the user to edit his details, what I dont want him to be able to edit is the "EmailAddress" field, so I have used Html.DisplayFor(m => m.EmailAddress).

但是,当这种形式这贴,我得到的所有值预期EmailAddress的。

But when this form this posted, I get all the values expect the EmailAddress.

我如何获得的电子邮件地址?如果我用一些其他的辅助性比使用 DisplayFor

How do I get the email address ? Should I have used some other helper than using DisplayFor ?

@using (Html.BeginForm()) {
@Html.ValidationSummary(true, "Account updation was unsuccessful. Please correct the errors and try again.")
<div>
    <fieldset>
        <legend>Update Account Information</legend>

        <div class="editor-label">
            @Html.LabelFor(m => m.EmailAddress)
        </div>
        <div class="editor-field">
            @Html.DisplayFor(m => m.EmailAddress)
            @*@Html.ValidationMessageFor(m => m.EmailAddress)*@
        </div>           

        <div class="editor-label">
            @Html.LabelFor(m => m.FirstName)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(m => m.FirstName)
            @Html.ValidationMessageFor(m => m.FirstName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(m => m.LastName)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(m => m.LastName)
            @Html.ValidationMessageFor(m => m.LastName)
        </div>            

        <p>
            <input type="submit" value="Update" />                
        </p>
    </fieldset>
</div>

}

请咨询我关于这个。

推荐答案

您将需要添加一个

@Html.HiddenFor(m => m.EmailAddress)

DisplayFor 不会在POST发送任何东西,它不会产生输入...

DisplayFor won't send anything in POST, it won't create an input...

顺便说一句,一个

@ Html.HiddenFor(M = GT; m.Id)//或任何这是模型的关键

将是有益的。

这篇关于Html.DisplayFor不张贴值ASP.NET MVC 3到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 09:54