c# - 在 MVC4 Twitter Bootstrap C# 中设置文本框格式

标签 c# asp.net-mvc-4 twitter-bootstrap visual-studio-2012 view

我已经尝试了许多使用 VS2012 将 Twitter Bootstrap 实现到 MVC4 的教程,同时仍然尝试保留身份验证代码(即使用 Internet 应用程序)。

我的问题是,当我使用脚手架来执行我定义的模型的所有 CRUD 页面时,它不使用 twitter bootstrap 格式。

这是生成的代码:

    <div class="editor-label">
        @Html.LabelFor(model => model.lastName)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.lastName)
        @Html.ValidationMessageFor(model => model.lastName)

输出是一个正常的编辑框,而不是带有蓝色轮廓的漂亮 Twitter 框等......

所以我尝试了:

        @Html.TextBox("Test","",new {@class="form-control"})

并且渲染得非常完美......所以我尝试了:

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

随后它就不起作用了。

请有人建议我如何解决这个问题,或者我在哪里可以下载与 MVC4 集成的 Twitter-bootstrap 的预制模板,这样我就可以开始编程。

我可以提供所需的任何其他代码。

提前致谢

最佳答案

那是因为你使用的方法

@Html.EditorFor( Expression<Func<TModel, TValue>> expression, object additionalViewData )

不像 @Html.Textbox-Helper 那样期望“htmlAttributes”。

你可以使用

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

关于c# - 在 MVC4 Twitter Bootstrap C# 中设置文本框格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20214004/

相关文章:

c# - 更改 ConcurrentBag 中的对象?

c# - 使用 C# 将 SVG 转换为 PNG

c# - Entity Framework 探查器 - ASP.NET MVC4 与 EF 6 - 无法确定提供者名称

javascript - 用户离开字段后立即显示 AngularJS Bootstrap 工具提示以进行客户端验证

php - 使用 AJAX 和 PHP 上传文件出现未知错误(BIF jQuery 插件)

twitter-bootstrap - Twitter bootstrap 侧边栏导航词缀

c# - Entity Framework 模型第一个导航属性添加无效的列名来查询?

c# - 如何在共享应用程序资源中实现导航按钮?

c# - 在 Azure 中部署 MVC 站点时出错

c# - 错误 "CommentsController does not have a default constructor"