Sil*_*ind 7 c# razor asp.net-mvc-4
我已经设置了一个VirtualPathProvider,它可以正常工作,如http://.../home/index地址栏中的直接网址调用.
public class HomeController
{
public ActionResult Index()
{
// This triggers MyVirtualPathProvider functionallity when called via
// the browsers address bar or anchor tag click for that matter.
// But it does not trigger MyVirtualPathProvider for 'in-view' calls like
// @{ Html.RenderAction("index", "home"); }
return View();
}
}
public class MyVirtualPathProvider : VirtualPathProvider
{
public override System.Web.Hosting.VirtualFile GetFile(string virtualPath)
{
// This method gets hit after the Controller call for return View(...);
if (MyCondition)
return MyVirtualFileHandler.Get(virtualPath);
return base.GetFile(virtualPath);
}
public override bool FileExists(string virtualPath)
{
// This method gets hit after the Controller call for return View(...);
if (MyCondition)
return true;
return base.FileExists(virtualPath);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我希望这也适用于Html帮助程序,但是现在它忽略VirtualPathProvider了视图中的html帮助程序调用:
@{
Html.RenderAction("index", "home");
}
Run Code Online (Sandbox Code Playgroud)
有没有办法解决这个问题?
另外,我有一个WebViewPage的覆盖,所以我可以覆盖帮助器的初始化,但我还没有得到什么或如何的线索.
编辑:
我在两台计算机上试过这个,奇怪的是,它可以在另一台计算机上运行.所以问题实际上会变成:
为什么VirtualPathProvider在一台计算机上运行,在另一台计算机上运行50%?但那么这个问题就会变得有点模糊,甚至是投机性的.尽管如此,我对此并不满意,但似乎我不得不重新安装一些东西.:(
用户 LostInComputer 非常友善地提供了一个在我的笔记本上运行的示例项目,但我对其中的区别感到困惑。
通常人们确实会期望 Html 助手只为 工作VirtualPathProvider,现在我知道它应该工作。
实际的问题在于我在特定电脑的安装中遇到了问题,重新安装后一切正常。所以这并不是一个真正复杂的解决方案,但由于很少有人关注这个问题,我至少给出了我自己的答案,因为有一天这可能对其他人有用,但它可能会多么乏味。:)
当您肯定希望某些东西能够工作时,您总是可以尝试在另一台机器上运行它(当然,如果您有一台可用的机器),因为最终所有可能的错误可能只是安装损坏。:(
| 归档时间: |
|
| 查看次数: |
263 次 |
| 最近记录: |