如何设置和获取asp.net mvc 3或mvc 4中的hiddenfield值 [英] how to set and get the hiddenfield value in asp.net mvc 3 or mvc 4

查看:103
本文介绍了如何设置和获取asp.net mvc 3或mvc 4中的hiddenfield值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





有场景我想查看所有表格控件值。



为此我创建了隐藏字段。



并在视图中使用了post方法(@ Html.Hidden(HProjectTypeId,Model.ProductTypeId);





但是在控制器中我得到了空值..



我很高兴mvc请指导我。



问候

ruc。

Hi,

there is scenario i want to check the all the form controls values.

for this i was created the hidden field .

and was used the post method in view( @Html.Hidden("HProjectTypeId", Model.ProductTypeId);,


but in controller i was im getting null value..

im very new to mvc kindly guide me.

Regards
ruc.

推荐答案

好吧,隐藏字段就像其他字段一样。虽然最好使用 HiddenFor [ ^ ]方法而不是隐藏 [ ^ ]如果可能,您应该使用名称 HProjectTypeId 呈现隐藏字段,并且模型中的值.ProductTypeId 你应该在浏览器中查看,亲自查看。

但是,你在行动中得到的东西取决于许多事情。大多数关于自动映射,它工作得很好,但它无法猜测你的想法。这就是您应该使用... For方法的原因,因为它们将使用与映射器使用的逻辑相同的逻辑生成字段名称。 所以检查字段名称:在模型的属性名称中也是开头的H?如果没有,请删除它!



如果你发布模型,你发布的视图和动作(只有原型,而不是方法体)我可以准确地告诉你你错过了什么。
Well, hidden fields are just like other fields. Although it is better using the HiddenFor[^] method instead of Hidden[^] if possible, you should have a hidden field rendered with name HProjectTypeId and the value from Model.ProductTypeId. You should check in the browser, to see it for yourself.
But, what you get back in the action depends on many things. Most on the automatic mapping, which is working really good, but it can''t guess your thoughts. This is why you should use "...For" methods, because they will generate field names using the same logic as the mapper uses. So check the field name: is the "H" at the beginning also in the model''s property name? If not, remove it!

If you post the model, the view and the action (only the prototype, not the method body) you are posting to, I can tell you precisely what you are missing.


这篇关于如何设置和获取asp.net mvc 3或mvc 4中的hiddenfield值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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