当属性值来自模型中的属性时,如何设置css属性或属性?
例如,我想更改正文背景颜色,背景颜色的值是@ Model.BgColor。 @ model.BgColor从sql数据库获取数据。
我不知道如何从css中的模型中获取BgColor属性。当我在_Layout中尝试使用此设置时,我得到一个错误,即对象引用未设置为对象的实例。:
@model ItbTid.Models.DynCss
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<style>
body{
background-color:@Model.BgColor;
}
</style>
</head>
要点: 如何设置具有位于DynCss模型中的属性的元素的css属性值,该属性从数据库获取数据