我有一个模式对话框,我想根据模型中的值更改模式标题的颜色。我怎样才能最好地做到这一点? Model.AlertType.Description
包含我要用于更改标题颜色的值(严重=红色,警告=黄色,信息=绿色)
编辑:我在这方面没有很多经验,所以我不确定我缺少什么。我更改了div类,使其与在以下链接中找到的内容相匹配,以作为指导: https://www.bootply.com/s6x5oKLiDG
@model AgRSys.Models.Alerts
<div class="container">
<div id="display-alerts-modal-dialog" class="modal-dialog" role="dialog">
<div class="modal-content">
<div class="modal-header modal-header-primary">
<button type="button" class="modal-header-close close" data-
dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title " id="myModal-label">Model.AlertType.Description </h4>
</div>
<div id="modal-body" class="form-group modal-body">
@using (Ajax.BeginForm("DisplayAlert", ViewContext.RouteData.GetRequiredString("controller"), new { LID = Model.RelatedId }, new AjaxOptions { UpdateTargetId = "alerts-grid-body", OnFailure = "onFailure", OnSuccess = "onDisplayAlertSuccess", HttpMethod = "POST", InsertionMode = InsertionMode.Replace }))
{
<div id="modal-body" class="form-group modal-body">
@Html.LabelFor(model => model.Alert, htmlAttributes: new { @class = "control-label" })
@Html.TextAreaFor(model => model.Alert, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Alert, "", new { @class = "text-danger" })
</div>
<div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal" id="btnCancel">Cancel</button>
</div>
}
</div>
</div>
</div>
答案 0 :(得分:0)
由于Model.AlertType.Description
似乎是一个字符串,并且其值在link处与之相对应,因此请尝试跟随Razor:
<div class="modal-header modal-header-@(Model.AlertType.Description.ToLower().Trim())">
此行假定Model.AlertType.Description
返回以下值:
success, primary, info, warning, danger
这是已修复的视图cshtml代码:
@model AgRSys.Models.Alerts
<div class="container">
<div id="display-alerts-modal-dialog" class="modal-dialog" role="dialog">
<div class="modal-content">
<div class="modal-header modal-header-@(Model.AlertType.Description.ToLower().Trim())"> @*Here it is the fix*@
<button type="button" class="modal-header-close close" data-
dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title " id="myModal-label">Model.AlertType.Description </h4>
</div>
<div id="modal-body" class="form-group modal-body">
@using (Ajax.BeginForm("DisplayAlert", ViewContext.RouteData.GetRequiredString("controller"), new { LID = Model.RelatedId }, new AjaxOptions { UpdateTargetId = "alerts-grid-body", OnFailure = "onFailure", OnSuccess = "onDisplayAlertSuccess", HttpMethod = "POST", InsertionMode = InsertionMode.Replace }))
{
<div id="modal-body" class="form-group modal-body">
@Html.LabelFor(model => model.Alert, htmlAttributes: new { @class = "control-label" })
@Html.TextAreaFor(model => model.Alert, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Alert, "", new { @class = "text-danger" })
</div>
<div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal" id="btnCancel">Cancel</button>
</div>
}
</div>
</div>
</div>
</div>
它需要在以下行中追加到main.css文件:
/* CSS used here will be applied after bootstrap.css */
.modal-header-success {
color:#fff;
padding:9px 15px;
border-bottom:1px solid #eee;
background-color: #5cb85c;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.modal-header-warning {
color:#fff;
padding:9px 15px;
border-bottom:1px solid #eee;
background-color: #f0ad4e;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.modal-header-danger {
color:#fff;
padding:9px 15px;
border-bottom:1px solid #eee;
background-color: #d9534f;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.modal-header-info {
color:#fff;
padding:9px 15px;
border-bottom:1px solid #eee;
background-color: #5bc0de;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.modal-header-primary {
color:#fff;
padding:9px 15px;
border-bottom:1px solid #eee;
background-color: #428bca;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
答案 1 :(得分:0)
一旦我将新样式直接添加到文件中,它便解决了该问题。我已经将它们附加到应用程序中的另一个.CSS文件,但是它影响了应用程序中其他字段的字体样式。