为什么MVC Html.HiddenFor不会呈现我的领域? [英] Why mvc Html.HiddenFor does not render my field?

查看:174
本文介绍了为什么MVC Html.HiddenFor不会呈现我的领域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做到这一点简单的事

I'm trying to do this simple thing

<%= Html.HiddenFor(model => model.Id)%>

该模型

[HiddenInput(DisplayValue=true)]
public int Id { get; set; }

但我总是这样渲染

but i always get this rendered

<input type="hidden" value="0" name="UserInfo.Id" id="UserInfo_Id">

我已经检查和ID不是0 ..?!

i've check and the id is NOT 0.. ?!

需要一些解释在这里...

need some explanation here...

修改

问题似乎的是后期的事情下面mentionned。
这是工作

The problem seem's to be the post thing mentionned below. This is working

<input type="hidden" value="<%= Html.AttributeEncode(Model.Id) %>" id="<%= Html.IdFor(model=>model.Id)%>" name="<%= Html.NameFor(model=>model.Id)%>" />

由于马纳夫

推荐答案

我不知道,如果是这样的你,但 Html.HiddenFor()的情况下如果帖子中值改变不正确的输出值的帖子之后。这是一个不它被设计这样的错误。

I'm not sure if this is the case with you but the Html.HiddenFor() "do not output correct values after a post if the value is changed during the post." and this is a not a bug it was designed that way.

更多信息这里

快速修复:

不要使用帮手,试试这个来代替:

Don't use the helper, try this instead :

<input type="hidden" value="<%= Html.AttributeEncode(model.Id) %>" id="Id" name="Id" />

总是为我工作:)

Always worked for me :)

这篇关于为什么MVC Html.HiddenFor不会呈现我的领域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆