【问题标题】:CSS Class cannot be applied for EditorFor on ASPX C# view engineCSS 类不能应用于 ASPX C# 视图引擎上的 EditorFor
【发布时间】:2017-05-10 08:50:30
【问题描述】:

我使用基本的 html 属性和引导框架开发了一个 UI。 现在我想添加Html.EditorFor() 而不是<input type="text" class="form-control" />

我是这样添加的

<%= Html.EditorFor(model => model.Name,new { @class = "form-control" }) %>

但我的 html 页面无法呈现此内容。它显示了一个基本的 html 输入。 Bootstrap 类还没有应用在它上面。但是这个类属性适用于Hrml.TextBoxFor()

我正在使用ASPX C# 视图引擎。不是RAZOR

我经历了一些堆栈溢出问题和答案。根据大多数答案,我的语法是正确的。

如何在Html.EditorFor()...上应用css类?

【问题讨论】:

    标签: c# html css asp.net twitter-bootstrap


    【解决方案1】:

    Html.EditorFor 采用额外的ViewData 对象,而不是使用 TextBoxFor 等的普通 htmlAttributes。

    您需要做的就是将您的属性包装在一个附加对象中(与在 Razor 中的方式相同),方法是将您的调用更改为以下内容:

    <%= Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" }}) %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多