如何在编辑器模板上应用 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/