本文介绍了启用&安培;在剃刀视图禁用一个文本框(ASP.Net MVC 3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要基于价值(Model.CompanyNameEnabled)启用或禁用一个文本框。

下面code不工作。请纠正。

  @ {
                 字符串DISPLAYMODE =(Model.CompanyNameEnabled)? :已禁用=已禁用;
                @ Html.TextBox(公司名称,,新的{} DISPLAYMODE)
              }


解决方案

  @ {
   对象DISPLAYMODE =(Model.CompanyNameEnabled)?空:新{禁用=禁用};
   @ Html.TextBox(公司名称,,DISPLAYMODE)
}

您应该通过htmlAttribute匿名对象,具有属性名称= HTML属性名称,属性值=属性值。你的错误是,你传递字符串而不是名称=值对

I want to Enable or Disable a textbox based on the value (Model.CompanyNameEnabled).

The below code is not working. Please rectify.

             @{
                 string displayMode = (Model.CompanyNameEnabled) ? "" : "disabled = disabled";
                @Html.TextBox("CompanyName", "", new { displayMode })
              }
解决方案
@{
   object displayMode = (Model.CompanyNameEnabled) ? null : new {disabled = "disabled" };
   @Html.TextBox("CompanyName", "", displayMode)
}

You should pass htmlAttribute as anonymous object, with property names = html attribute names, property values = attribute values. Your mistake was that you were passing string instead of name=value pair

这篇关于启用&安培;在剃刀视图禁用一个文本框(ASP.Net MVC 3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 16:56