0
在MVC 3我能够把:MVC 4个变量在_Layout.cshtml
@{
string rootPath = HttpContext.Current.Request.ApplicationPath;
if (rootPath == "/")
{
rootPath = rootPath.Replace("/", "");
}
}
我_Layout.cshtml文件
,然后用ROOTPATH在我的任何其他意见,获得站点根目录。 我在MVC 4应用程序中尝试过同样的事情,除非将上面的代码放在同一个视图文件中,我试图使用rootPath,否则它不起作用。 有没有其他人碰到过这个问题?
使用'ViewBag',你的'if'语句似乎有点多余,当你已经知道输入时,为什么还要打扰'.Replace()'。这可能只是: if(rootPath ==“/”) { rootPath = string.Empty; } – Brendan