如何在mvc app上的编辑器模板模型对象上应用样式

时间:2016-08-25 03:43:55

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

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

@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

1 个答案:

答案 0 :(得分:0)

在EditorTemplate文件中,您可以获得htmlAttributes并使用如下所示:

@model string

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

@Html.TextBoxFor(x => x, htmlAttributes)
相关问题