I am trying to build a website in C# using MVC3 with Razor. I have to build it with themes, but I have problems setting a dynamic content to Url.Content, like it follows:
<img src="@Url.Content("~/Content/themes/THEME-NAME/images/logo.png")" alt="logo" />
and I would like to set the value of THEME-NAME from my code. Let's say from an Application object. Is it possible?
Give the ViewBag a shot.
in your controller action I would put :
ViewBag.ThemeName = "SomeName";
in your view :
<img src="@Url.Content("~/Content/themes/"+ViewBag.ThemeName+"/images/logo.png")" alt="logo" />Answer2:
Would something like the code show below work for you? did not test it but may lead you in the right direction.
var themName = somevalue var urlValue = "~/Content/themes/" + @themeName + "/images/logo.png" <img src="@Url.Content(@urlValue)" alt="logo" />