【问题标题】:Remove default Html.TextBoxFor inline style删除默认 Html.TextBoxFor 内联样式
【发布时间】:2013-02-06 10:32:11
【问题描述】:

我有一个非常基本的表单,我使用模型从视图中渲染。 在这种形式中,我有一些像这样的文本输入:

<div class="editor-label">
     @Html.LabelFor(model => model.UserProfile.FirstName)
</div>
<div class="editor-field">
     @Html.TextBoxFor(model => model.UserProfile.FirstName)
     @Html.ValidationMessageFor(model => model.UserProfile.FirstName)
</div>

当它在网页上呈现时,它包含这种讨厌的内联样式:

<input 
id="UserProfile_FirstName" 
name="UserProfile.FirstName" 
type="text" 
value="xxx"
sourceindex="4" 
style="border-style: solid; border-width: 1px; 
    border-color: rgb(238, 50, 50) rgb(240, 80, 80) rgb(240, 80, 80); 
    box-shadow: rgb(250, 230, 230) 1px 1px inset; 
    -webkit-box-shadow: rgb(250, 230, 230) 1px 1px inset;">

我尝试了几种方法来删除它,包括

@Html.TextBoxFor(model => model.UserProfile.LastName, null, 
{ @style = "border-width: 0px;" })

类似,但我添加的内联样式是在我要删除的样式之前添加的,因此它们会被覆盖。

如何删除或覆盖此内联样式?

【问题讨论】:

    标签: razor asp.net-mvc-4 html-helper inline-styles


    【解决方案1】:

    我认为这不是 TextBoxFor 助手的默认行为。你有在页面上运行的任何 jQuery 插件吗?尤其是可能注入像这样的内联样式的那个?

    【讨论】:

    • 是的,过了一会儿我也想到了这个问题。我在网站上有 jquery 1.8.3(jquery、jquery-ui、jquery.unobtrusive 和 jquery.validate)和现代化工具。我尝试从站点中删除 jquery.validate 并且它消失了。但我不想不使用 jquery.validate。但我想这是另一个帖子的问题。至少我找到了罪魁祸首。谢谢。
    • 这真的很奇怪。我以前没有见过 jquery.validate 这样做。我认为它与 jQuery 有关,因为 HtmlHelper 的源代码不应用任何样式属性。
    猜你喜欢
    • 2011-12-19
    • 2014-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-25
    • 2016-08-05
    相关资源
    最近更新 更多