简体   繁体   English

CSS类不能应用于ASPX C#视图引擎上的EditorFor

[英]CSS Class cannot be applied for EditorFor on ASPX C# view engine

I have developed a UI using basic html attributes and bootstrap framework. 我已经使用基本的html属性和引导框架开发了一个UI。 Now I want to add Html.EditorFor() instead of <input type="text" class="form-control" /> . 现在,我想添加Html.EditorFor()而不是<input type="text" class="form-control" />

I added it in this way 我以这种方式添加了它

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

but my html page cannot render this. 但我的html页面无法呈现此内容。 It shows a basic html input. 它显示了基本的html输入。 Bootstrap class has not been applied on it. Bootstrap类尚未应用。 But this class attribute is working for Hrml.TextBoxFor() 但是此类属性适用于Hrml.TextBoxFor()

I'm using ASPX C# View Engine. 我正在使用ASPX C# View Engine。 Not RAZOR . 不是RAZOR

I went through some stack-overflow questions and answers. 我经历了一些堆栈溢出问题和解答。 According to the most answers, my syntax is correct. 根据大多数答案,我的语法是正确的。

How to apply css classe on Html.EditorFor() ...? 如何在Html.EditorFor()上应用CSS类?

Html.EditorFor takes an additionalViewData object rather than the normal htmlAttributes that you have with TextBoxFor, etc. Html.EditorFor需要一个额外的ViewData对象,而不是TextBoxFor等具有的常规htmlAttributes。

All you should need to do is wrap your attributes in an additional object (in the same way as you would in Razor) by changing your call to the following: 您需要做的就是通过将调用更改为以下内容,将属性包装在其他对象中(与在Razor中相同):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM