本文介绍了MVCSiteMapProvider不会将Razor模板用于菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我现在很喜欢通过Nuget使用完善的MVCSiteMapProvider,但遇到了障碍.

I'm enjoying using the well-made MVCSiteMapProvider through Nuget at the moment but I've hit a roadblock.

我正在尝试为 @ Html.MvcSiteMap().Menu()帮助器修改模板.我正在修改的文件是 .. \ Views \ Shared \ DisplayTemplates \ MenuHelperModel.cshtml ,无论我对该文件进行什么更改,模板在渲染时都不会更新.

I'm trying to modify the template for the @Html.MvcSiteMap().Menu() helper. The file I'm modifying is ..\Views\Shared\DisplayTemplates\MenuHelperModel.cshtml and no matter what change I make to the file, the template does not update when rendered.

我用notepad ++完成了查找全部"功能,发现在 MvcSiteMapProvider.dll 中有两个模板,一个用于经典的asp.net,一个用于Razor.很明显,.dll文件中的模板正在被调用-但是如何使这种情况不成立?

I've done a Find All with notepad++ and found that within MvcSiteMapProvider.dll there is two templates, one for classic asp.net and one for Razor. So clearly the template within the .dll file is being called - but how do I make this not the case?

也许值得知道的是,尽管模板位于 .. \ Views \ Shared \ DisplayTemplates \ 中,但该站点已配置为对View使用不同的文件夹.

It may be worth knowing that although the templates are located in ..\Views\Shared\DisplayTemplates\, the site is configured to use a different folder for Views.

同样,如果我将模板名称传递给助手,仍然无效.

edit: also if I pass in a template name to the helper, still no effect.

推荐答案

模板化助手是MVC创建的,而不是 MvcSiteMapProvider 之一.我强烈怀疑您的问题是由于重新配置了Views文件夹造成的. MVC不支持重新配置模板文件夹的方式.

Templated helpers are an MVC creation, not one of MvcSiteMapProvider. I strongly suspect your issue is due to reconfiguring your Views folder. MVC does not support a way to reconfigure your templates folder.

但是正如接受的答案中指出的那样,可以将它们放在〜/Views/CurrentController/DisplayTemplates/下.您可能可以使用该功能将模板放入新配置的文件夹中.不过,这意味着您需要为每个单个控制器添加模板的副本.

But as pointed out in the accepted answer, it is possible to put them under ~/Views/CurrentController/DisplayTemplates/. You might be able to use that feature to put the templates in your newly configured folders. This means that you would need to add a copy of the templates for every single controller, though.

最好的解决方案是不要更改MVC文件夹的默认设置.

The best solution is not to change the MVC folders from their defaults.

如果这不是一种选择,则可以考虑基于.cs"rel =" nofollow noreferrer>来自当前代码的代码,该代码返回 HtmlString 而不是使用模板.

If that is not an option, you might consider rolling your own Menu HTML helper based on the code from the current one that returns an HtmlString rather than using templates.

模板化的帮助程序更好,因为您可以在部署代码后对其进行编辑(这就是我们这样做的原因),但同时需要注意的是,您必须依靠MVC的默认文件夹结构来使用它们.

The templated helpers are better because you can edit the code after it is deployed (which is why we did it that way), but it comes with the caveat that you have to rely on MVC's default folder structure to use them.

这篇关于MVCSiteMapProvider不会将Razor模板用于菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 09:49