As a developer, I have my own perspective on a .css
file.
@model StyleProfile
body {
color: @Model.color;
}
This code is included in my layout:
<link href="@Url.Action("CssDynamic")" rel="stylesheet" type="text/css" />
In my controller, I have the following setup:
public class HomeController : Controller
{
private OnepageCMSEntities db = new OnepageCMSEntities();
public ActionResult CssDynamic()
{
var model = db.StyleProfiles.FirstOrDefault();
return new CssViewResult();
}
}
public class CssViewResult : PartialViewResult
{
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "text/css";
base.ExecuteResult(context);
}
}
Everything works smoothly. However, I encountered an issue when trying to pass a model object in the "CssDynamic" ActionMethod
:
return new CssViewResult(model);
An error message popped up saying:
"this does not contain a constructor that takes 1 arguments.
To address this problem, what changes should be made to the CssViewResult
class?