如何指定为Html.TextBox辅助属性,同时保持从ViewData的价值检索? [英] How do I specify attributes for a Html.TextBox helper while maintaining the value retrieval from ViewData?

查看:121
本文介绍了如何指定为Html.TextBox辅助属性,同时保持从ViewData的价值检索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Html.TextBox帮助创建文本框。我想设置文本框,我的理解使用以下过载完成属性:

I am using the Html.TextBox helper to create textboxes. I want to set attributes on the textbox, which I understand is done using the following overload:

Html.TextBox(字符串名称,对象的值,对象htmlAttributes)

不过,我想保持那里的HTML辅助自动无论从ViewData的或ViewData.Model使用值的功能,我不明白的方式,只是指定名称和htmlAttributes。这可能吗?

However, I want to maintain the functionality where the HTML helper automatically uses the value from either ViewData or ViewData.Model and I do not see a way to just specify the name and the htmlAttributes. Is this possible?

推荐答案

源$ C ​​$之后ç,似乎所有你需要做的就是指定在需要一个名称,值和htmlAttributes签名为空值。如果该值为null,它会尝试使用从ViewData的价值。

After looking at the source code, it appears that all you need to do is specify the value as null in the signature that takes a name, value, and htmlAttributes. If the value is null, it will attempt to use the value from the ViewData.

Html.TextBox( "name", null, new { @class = "css-class" } );

这篇关于如何指定为Html.TextBox辅助属性,同时保持从ViewData的价值检索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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