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.

I was using custom Foo.CSCSS as view where my razor CSS was held. And MyViewModel gets data from DB.

Like this.

public MongoDatabase Mongo;
    [HttpPost]
            public ActionResult Foo(string Input)
            {
                var collection = Mongo.GetCollection<MyViewModel>(Input);
                var model = collection.FindAll().ToList<MyViewModel>().FirstOrDefault();
    return View(model);

    @using (Html.BeginForm("Foo", "Styles", FormMethod.Post))
    {
        <fieldset>
            <label for="sub">Get you CSS.</label>
            <br />
            <input id="txtEmail" type="text" name="Input" placeholder="Type in an CSS collection" required>
            <input type="submit" name="submit" value="Press">
        </fieldset>

Returns me a CSS as view instead of just inserting it as CSS.

@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;
}

Is there a fix for that?

public ActionResult Foo()
        {
            var collection = Mongo.GetCollection<MyViewModel>("CollectionName");
            var model = collection.FindAll().ToList<MyViewModel>().FirstOrDefault();
return View(model);

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.

I took This as Example Dynamic Stylesheets Using Razor

Related posts

Recent Viewed