- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我已经设置了一个 VirtualPathProvider
,它可以很好地用于地址栏中的直接 url 调用,例如 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);
}
}
但是,我希望这也适用于 Html 助手,但现在它忽略了 View 中 html 助手调用的 VirtualPathProvider
:
@{
Html.RenderAction("index", "home");
}
有没有办法解决这个问题?
此外,我有一个 WebViewPage 的覆盖,所以我可以覆盖助手的初始化,但我不知道是什么或如何。
编辑:
我已经在两台电脑上试过了,奇怪的是,它在另一台电脑上也能正常工作。所以问题实际上变成了:
为什么 VirtualPathProvider 在一台计算机上工作,而在另一台计算机上失败 50%?但随后这个问题会变得有些模糊,甚至是推测性的。尽管如此,我对此并不满意,但似乎我必须重新安装一些东西。 :(
最佳答案
用户 LostInComputer 非常友好地交出了一个在我的笔记本上运行的示例项目,我很困惑会有什么不同。
通常人们会期望 Html 助手确实只是为 VirtualPathProvider
工作,现在我知道它应该。
实际问题出在我遇到问题的特定电脑的安装上,重新安装后一切正常。所以这并不是一个真正复杂的解决方案,但由于很少有人关注这个问题,我至少给出了我自己的答案,因为有一天这可能对其他人有用,它可能会多么乏味。 :)
当您肯定希望某些东西能正常工作时,您总是可以尝试在另一台机器上运行它(当然如果您有可用的机器),因为最终所有可能出错的可能只是一个损坏的安装。 :(
关于c# - Html 助手不使用自定义 VirtualPathProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20608672/
有时我需要(为了让我的开发更快)在我的代码中对一些东西进行硬编码。这可能是凭据,或者可能只是一个允许我测试某些功能的 hack。由于很多原因,我从来不想将这段代码推送到主代码库甚至开发分支。一段时间以
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 2 年前。 Improve this qu
我经常发现自己从类中提取常见行为到只包含一组静态方法的帮助程序/实用程序类中。我经常想知道是否应该将这些类声明为抽象类,因为我真的想不出实例化这些类的正当理由? 将这样的类声明为抽象类的优点和缺点是什
如果我这样做: $obj = factory(Object::class)->make(); collect($obj); 我返回了一个类型的集合: Illuminate\Support\Collec
我有一个应用程序,我可以在其中列出 parent 和 child 。当我添加一个 child 时,我需要获得一个 parent 列表作为下拉列表显示。有没有类似 collection_select 的
我有渲染组件( source ),用于从 Controller 字段渲染组件/助手。它适用于 ember 1.9.1,但在更新到 ember 1.12.1 后,我发现 API 发生了变化。之后upda
我刚开始使用 Rails,还有很多东西需要学习,所以我可能会比平常更频繁地在 Stackoverflow 上询问初学者 Rails/Ruby 问题。 我只是想弄清楚 Helpers 在 Rails 中
我在 Web 上使用 VS Express 2012。我的项目是一个 MVC 4 项目。 我正在尝试创建一个助手来创建一个菜单项,该菜单项是带有标签的 png 图像。我几乎剪切并粘贴了这段代码: Ac
我正在尝试在我的 Vue 页面中映射我商店的状态变量: export default { data: () => ({ localData: []
我目前正在开发一个 Rails 插件,用于生成 iPhone 特定的 HTML 元标记。我尝试使用 ActionView::TestCase 进行单元测试,但不断收到相同的错误。请参阅下面的文件内容和
我正在努力解决一个与变量声明相关的非常基本的问题。我已经阅读了有关变量的所有内容,但我不知道我的问题是否与 1) 我如何声明变量或 2) 我如何设置变量的范围有关。 首先,我对 Meteor 中变量的
我想知道是否可以将参数传递给 Meteor Helper 并在 HTML 中插入返回对象的属性,而不仅仅是返回最终值。我有这样的东西: HTML: {{#each conversation}}
我正在尝试为我的 Ember 应用程序构建一个新的条件助手。值得一提的是,我正在使用使用 Handlebars 2.0 的 Ember 1.10.1,并且我无法升级它,如果能很好地解决这个版本的 Em
我最近从 Dreamweaver 迁移到 aptana,并尝试使 aptana 尽可能相似;) 已经做了很多更改,但我仍然找不到使代码字体变小的方法(在 Dreamweaver 中代码更清晰,因为字体
我有以下模板: {{#each helperOne "1" "2" }} Lorem upsom {{#each}} helper : template.tempName.h
我有这个简单的代码块,它位于我的一个模板上,但我想将其作为助手放置,以便我的所有 View 都可以访问它。 @hidden(field: Field) = { @defining(field)
使用正则表达式,我正在替换 **text in bold**至 text in bold在一个字符串中,然后显示 message使用 {{{message}}}在我的 EmberJS 模板上。问题是我
是否有任何非常有用和健壮的 C++ 网络库?和库来帮助他们更好地运行?诸如使用 << 时自动进行字节序转换之类的东西,阻止读取直到结构或 w/e 您的读取完全传输,有助于调试协议(protocol)的
模板 {{#each tags}} {{#isObject this}} Object {{else}}
我有返回 JSON 的函数: Template.mainmenu.menuitem = function() { var jsonObj = { items: [ { ur
我是一名优秀的程序员,十分优秀!