为什么DisplayFor不将值发布到操作方法? [英] Why DisplayFor does not post values to Action Method?

查看:33
本文介绍了为什么DisplayFor不将值发布到操作方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们使用下面的表单将表单发布到操作方法"时,我们可以在参数"中看到视图模型"值.

When we post the form using below to Action Method, we can see the View Model values in Parameter.

@Html.EditorFor(model => model.Foo)

当我们使用下面的表单将表单发布到操作方法"时,看不到参数"中的视图模型"值.

When we post the form using below to Action Method, we can't see the View Model values in Parameter.

@Html.DisplayFor(model => model.Foo)

因此,在以后的情况下,我们可以使用隐藏字段".因此,我认为,不应该使用 DisplayFor 来发布表单值.

So, in later case, w could us Hidden Fields. So, I think, w should not us DisplayFor when it comes o post form values.

问题:为什么 DisplayFor 不将值发布到操作方法?我们可以讨论一下内部机制吗?

Question : Why DisplayFor does not post values to Action Method? Can we discuss the internal mechanism for this ?

推荐答案

请参见html渲染.没有属性 name .或者不是输入标签.表单标签仅发送具有属性 name 的标签元素 input,select,textarea ...... .例如:

see the html rendering. does not have the attribute name. or not an input tag. the form tag only send tag elements input, select, textarea,... that have the attribute name. For example:

<form...>
   <input id="lastname" name="lastname" />
</form>

不是这个:

<form...>
   <input id="lastname" />
</form>

这篇关于为什么DisplayFor不将值发布到操作方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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