我怎么设置asp.net-MVC上HTML文本框disabled属性? [英] how do I set disabled attribute on html textbox in asp.net-mvc?

查看:1519
本文介绍了我怎么设置asp.net-MVC上HTML文本框disabled属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态设置的HTML文本框的disabled属性和有问题

I am trying to dynamically set the disabled attribute on the html textbox and having issues

我想这在我看来:

 string disabledString = "";
 if (SomeLogic)
 {
      disabledString = "disabled";
 }

 Html.Textbox()...new Dictionary<string, object> { { "maxlength", 50 }, { "disabled", readOnlyState } })%>

正如你可以看到我设置disabled属性为或禁用,但是当我测试,似乎在任何情况下被禁用。
我缺少的东西吗?

As you can see I am setting the disabled attribute to "" or disabled but when I test, it seems to be disabled in either case. Am I missing something?

推荐答案

这是丑陋的对我们来说,由于事实,即HTML规范是烂在这里。

This was ugly for us, due to the fact that the HTML spec is lousy here.

基本上在我们看来,code,我们有一些逻辑是这样的:

Basically in our view code we had some logic like this:

bool isPlatformOwner = false;

object disabledAttributes = new { @disabled="disabled", @readonly="readonly" };

//omitted code setting isPlatformOwner    

    if (isPlatformOwner)
    {
        disabledAttributes = new { };
    }

然后,我们的控制,我们有这样的:

Then, for our controls, we had this:

<%=Html.CheckBoxFor(f => f.AddToReleaseIndicator, disabledAttributes)%>

匿名类型在这里救了我们,但是,就像我说的,这有点难看。

Anonymous types saved us here, but, like I said, it got a little ugly.

这篇关于我怎么设置asp.net-MVC上HTML文本框disabled属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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