css - 如何在 mvc 应用程序的编辑器模板模型对象上应用样式

标签 css asp.net-mvc twitter-bootstrap asp.net-mvc-4 bootstrap-modal

如何在编辑器模板上应用 Bootstrap 样式

@Html.EditorFor(model => model.AddressDetails) 

我试过像下面这样添加 htmlAttributes

@Html.EditorFor(model => model.AddressDetails, new { htmlAttributes = new { @class = "col-md-4 col-md-4 col-md-4  bounceIn" }, })

model.AddressDetails 有多个属性,我需要在多行的 3 列中显示。

public class AddressDetails
{
    [Required]
    public string AddressLine1 { get; set; }
    public string AddressLine2 { get; set; }
    public string AddressLine3 { get; set; }
    public string AddressLine4 { get; set; }
    public string AddressLine5 { get; set; }
    public string AddressLine6 { get; set; }
    public string City { get; set; }
    public string Country { get; set; } 

但结果是第一行有 3 列,而下一行则分散在各处。对齐错误。

我认为我的编码方式是错误的。我正在使用 Bootstrapp v3.1.1

最佳答案

在 EditorTemplate 文件中,您可以获取 htmlAttributes 并使用如下方式:

@model string

@{
    var htmlAttributes = ViewData["htmlAttributes"] ?? new { };
}

@Html.TextBoxFor(x => x, htmlAttributes)

关于css - 如何在 mvc 应用程序的编辑器模板模型对象上应用样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39136357/

相关文章:

html - 搜索图标移出 div,在 chrome 中工作正常但在 mozilla 中不工作

css - 在eclipse动态web元素中,如何将css链接到webcontent文件夹中的jsp文件

html - 将 div 拉伸(stretch)到固定宽度元素内的全宽

twitter-bootstrap - Bootstrap 文本框未拉伸(stretch)全宽

asp.net-mvc - Web API + ODataQueryOptions + $top 或 $skip 导致 SqlException

jquery - Bootstrap popover 右上角总是在最上面

javascript - 缩放时自定义传单 divIcon 不会停留在固定标记位置

css - Bootstrap 4 悬停在导航栏链接上会导致闪烁

asp.net-mvc - 用于重定向的 www 或 http www

c# - @Html.Dropdownlist C# MVC 4 当 bool = true 时显示 div