动态Url.Content [英] dynamic Url.Content

查看:156
本文介绍了动态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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆