本文介绍了动态Url.Content的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想建立使用MVC3剃刀在C#中的网站。我有一个主题来构建它,但我有问题设置动态内容Url.Content,就像如下:
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" />和我想从我的code设置主题名称的值。让我们从一个应用程序对象说。这可能吗?
and I would like to set the value of THEME-NAME from my code. Let's say from an Application object. Is it possible?
感谢。
推荐答案给这个ViewBag出手了。
Give the ViewBag a shot.
在你的控制器动作我会把:
in your controller action I would put :
ViewBag.ThemeName = "SomeName";在您的视图:
<img src="@Url.Content("~/Content/themes/"+ViewBag.ThemeName+"/images/logo.png")" alt="logo" />更多推荐
动态Url.Content
发布评论