如何创建使用HTML帮助中的asp.net的MVC只读文本? [英] How to create a readonly text using html helper in asp.net mvc?

查看:98
本文介绍了如何创建使用HTML帮助中的asp.net的MVC只读文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要禁用在视图中的文本框。所以我用以下code:

I want to disable a textbox in the view. So I use following code:

<%= Html.TextBox("ID", Model.ID, new { readonly="true" })%>

<%= Html.TextBox("ID", Model.ID, new { enable="false" })%>

他们都不起作用。有什么解决方案?

Both of them don't work. what's the solution?

推荐答案

尝试

<%= Html.TextBox("ID", Model.ID, new { @readonly="readonly" })%>

我不知道你有使用过载有4个参数。您应该能够使用3的人,但你需要追加@给只读只读以来在C#中的关键字。而@ReadOnly设置为只读是XHTML规范。

I'm not sure you have to use the overload with 4 parameters. You should be able to use the one with 3, but you need to append @ to the readonly since readonly is a keyword in C#. And setting @readonly to readonly is XHTML compliant.

这篇关于如何创建使用HTML帮助中的asp.net的MVC只读文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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