MVC5和Bootstrap3:Html.EditorFor错误的类?如何改变? [英] MVC5 and Bootstrap3: Html.EditorFor wrong class? How to change?

查看:254
本文介绍了MVC5和Bootstrap3:Html.EditorFor错误的类?如何改变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只注意到MVC使用5时EditorFor使用不同类的输入字段。我认为它从引导较低版本,所以当前的类并没有真正增加。

I just noticed that MVC 5 is using a different class for input fields when using EditorFor. I think its from a lower version of bootstrap, so the current class doesn't really add up.

我说的这一点:

<div class="form-group">
    @Html.LabelFor(model => model.Contact.CellphoneNo, new { @class = "control-label col-md-4"})
       <div class="col-md-8">
           @Html.EditorFor(model => model.Contact.CellphoneNo)
           @Html.ValidationMessageFor(model => model.Contact.CellphoneNo)
       </div>
</div>

这会导致这样:

<div class="form-group">
    <label class="control-label col-md-4" for="Contact_CellphoneNo">CellphoneNo</label>
    <div class="col-md-8">
        <input class="text-box single-line" id="Contact_CellphoneNo" name="Contact.CellphoneNo" type="text" value="">
        <span class="field-validation-valid" data-valmsg-for="Contact.CellphoneNo" data-valmsg-replace="true"></span>
    </div>
</div>

当你在看标签,它有一个文本框类,而不是Bootstrap3的表格控

When you look at the tag, it has a "text-box" class instead of Bootstrap3's "form-control"

我觉得我读周围的地方,这是由于MVC5开关在最后一分钟或东西来引导3的事实。

I think I read around somewhere that this was due to the fact of MVC5 switching to Bootstrap 3 at the last minute or something.

问题是:我如何手动更改类?我希望能够改变文本框的形式控制。我真的不能找到code虽然。

Question is: How do I change that class manually? I want to be able to change text-box to form-control. I can't really find the code though.

我也试过这已

@Html.EditorFor(model => model.CivilStatus, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.CivilStatus)

似乎没有哪个工作。我难倒。任何想法?

Which doesn't seem to work. I'm stumped. Any ideas?

在此先感谢!

推荐答案

EditorFor不接受HTML属性作为参数。您所使用的参数实际上是 additionalViewData

EditorFor doesn't accept HTML attributes as a parameter. The parameter you are using is actually additionalViewData

使用TextBoxFor而不是

Use TextBoxFor instead

@Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })

修改

由于MVC 5.1,HTML属性,可以使用此语法传递到EditorTemplate

As of MVC 5.1, HTML attributes can be passed to the EditorTemplate using this syntax

@Html.EditorFor(m => m.UserName, new { htmlAttributes = new { @class = "form-control" } })

这篇关于MVC5和Bootstrap3:Html.EditorFor错误的类?如何改变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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