[RESOLVED]Load resources from actions of a controller

Can I load css not like a file foo.com/file.css ? I want to use path like "foo.com/home/index/".

I suppose that you could point to a particular file and then load it when your View is rendered using something like the ViewBag (or Model) :

public ActionResult Test()
            // Find the appropriate absolute URL for your CSS file
            var url = Url.Content("~/Content/Site.css");
            // Or fully qualify one from an external, publicly accessible site (Bootstrap example)
            //var url = "http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css";

            // Build your URL and store it in the ViewBag
            ViewBag.CSS = String.Format(@"<link href='{0}' rel='stylesheet' type='text/css' />", HttpUtility.HtmlEncode(url));
            return View();

And then add the following within the <head> section of your View to render it :

    <meta name="viewport" content="width=device-width" />

which would render the tag within your View :

    <meta name="viewport" content="width=device-width">
    <link href="/Content/Site.css" rel="stylesheet" type="text/css">

Can I load css like a stream?

Leave a Reply