title: Dynamic CSS in Razor MVC
body: <p>I am trying to get different css on input. using Custom razor view Engine. and it works if I just take data from Database from 1 collction. but I want to alternate the CSS for lets say different users.</p>
  
  <p>I was using custom Foo.CSCSS as view where my razor CSS was held. And MyViewModel gets data from DB. </p>
  
  <p>Like this.</p>
  
  <pre><code>public MongoDatabase Mongo;
      [HttpPost]
              public ActionResult Foo(string Input)
              {
                  var collection = Mongo.GetCollection&lt;MyViewModel&gt;(Input);
                  var model = collection.FindAll().ToList&lt;MyViewModel&gt;().FirstOrDefault();
      return View(model);
  
      @using (Html.BeginForm("Foo", "Styles", FormMethod.Post))
      {
          &lt;fieldset&gt;
              &lt;label for="sub"&gt;Get you CSS.&lt;/label&gt;
              &lt;br /&gt;
              &lt;input id="txtEmail" type="text" name="Input" placeholder="Type in an CSS collection" required&gt;
              &lt;input type="submit" name="submit" value="Press"&gt;
          &lt;/fieldset&gt;
  </code></pre>
  
  <p>Returns me a CSS as view instead of just inserting it as CSS.</p>
  
  <pre><code>@model CustomViewEngine.Models.MyViewModel
  
  body {
      background-color: red;
  }
  
  div.col-md-4 {
      background-color: @Model.BGColor;
      text-decoration: @Model.TextDec;
      border-style: @Model.BRDStyle;
      border-width: @Model.BRDWidth;
  }
  div.yo {
  background-color: blue;
  }
  </code></pre>
  
  <p>Is there a fix for that?</p>
  
  <pre><code>public ActionResult Foo()
          {
              var collection = Mongo.GetCollection&lt;MyViewModel&gt;("CollectionName");
              var model = collection.FindAll().ToList&lt;MyViewModel&gt;().FirstOrDefault();
  return View(model);
  </code></pre>
  
  <p>Like this it works and gets data from DB. And uses it as CSS. I probably failed to explain the CSS is not exactly CSS it's a custom extension Foo.CSCSS, I parse and feed as View.</p>
  
  <p>I took This as Example <a href="https://stackoverflow.com/questions/10279873/dynamic-stylesheets-using-razor">Dynamic Stylesheets Using Razor</a></p>