Reputation: 1271
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?
Thanks.
Upvotes: 1
Views: 3679
Reputation: 3181
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" />
Upvotes: 2
Reputation: 2143
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" />
Upvotes: 0