【问题标题】:How to apply styles on editor template model object on mvc app如何在 mvc app 上的编辑器模板模型对象上应用样式
【发布时间】:2016-08-25 13:28:09
【问题描述】:

如何在编辑器模板上应用 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 列,而下一行则分散在各处。对齐错误。

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

【问题讨论】:

  • 您已标记此 MVC-4,但仅在 MVC-5.1 或更高版本中支持在 EditorFor() 中添加 html 属性
  • 我应用 html 属性的方式可能有问题。在 MVC 4 中我如何应用 html 属性?
  • @Html.TextBoxFor(m => m.AddressDetails, new { @class = "col-md-4 col-md-4 col-md-4 bounceIn" })
  • 我试过这个,但宽度仅适用于模型中的前 3 个属性。之后对齐是错误的。第五个属性 addressline5 不在第二列的正下方。我的意思是文本框控件不适合第二列
  • 哪 5 个属性? - 您显示的所有代码都是针对一个元素的。

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


【解决方案1】:

在 EditorTemplate 文件中,您可以通过以下方式获取和使用 htmlAttributes:

@model string

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    • 2015-04-05
    • 2011-08-14
    相关资源
    最近更新 更多