本文介绍了为何编译器没有在Orchard主题中找到我的剃刀助手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在视图之间共享从mediaPart创建img标签的逻辑.我已经创建了以下剃刀helper方法:

I would like to share among views the logic for creating an img tag from a mediaPart. I have already created the following razor helper method:

@helper CreateImgFromMediaPart(dynamic mediaPart, int width = 150)
{
    var imgSrc = mediaPart != null ? mediaPart.MediaUrl : string.Empty;
    var imgAlt = mediaPart != null ? mediaPart.AlternateText : string.Empty;
    <img alt="@imgAlt" src="@imgSrc" />
}

我已经尝试过通过创建App_Code文件夹,将MyHelpers.cshtml文件放入其中,然后将上述帮助方法放入该文件中来进行尝试.不幸的是,我们收到以下错误:

I have tried this by creating an App_Code folder, putting into it a MyHelpers.cshtml file, and putting in that file the above helper method. Unfortunately, we receive the following error:

推荐答案

您是否已将dll引用添加到views文件夹中的web.config?这就是用来解决特定于剃刀的帮助器/定义的方法.

Have you added the dll reference to the web.config in the views folder? This is what is used to resolve razor specific helper/definitions.

这篇关于为何编译器没有在Orchard主题中找到我的剃刀助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 08:02