无法识别App_Code中的剃刀视图内的全局帮助器

问题描述

编辑:在Rider中打开一个新的ASP.NET Web应用程序后,它可以工作,因此,我现在试图找出两个项目之间的主要区别是什么。

我使用的是Mono 6.8,特别是MVC版本5.3.2和.NET版本4.7.2,以及Jetbrains Rider IDE.E和Mac OS。

我执行了一个任务,以将针对不同平台的一些剃刀(.cshtml)视图分为两个,因此我想创建全局助手以避免代码重用。

对于每个视图,我都在/ App_Code文件夹中创建了另一个视图来容纳共享的帮助程序,但是在构建时,这些不被识别,我得到了(例如):

  The name 'ExtendedInfoHtmlHelpers' does not exist in the current context

其中一个全局帮助程序视图(App_Code / ExtendedInfoHtmlHelpers.cshtml)的一部分的示例:

@using System.Web.Mvc
@using System.Web.Mvc.Html
@using Shift6.Dashboard.viewmodels.Sessions
@using Shift6.Extensions
@using Shift6.Web
@using Shift6.Web.Extensions

@model Shift6.Dashboard.viewmodels.Sessions.SessionInfoviewmodel

@helper Title(SessionInfoviewmodel Model)
{
    <div id="extended-title" class="sessions-extended-title">

        @{
            var userNameString = string.IsNullOrEmpty(Model.ClientInfo.User.AppUserId) ? "Anonymous User #" : "User #";

            var appUserIdHeader = userNameString + Model.ClientInfo.User.UserAppIndex +
                                  (!string.IsNullOrEmpty(Model.ClientInfo.User.AppUserId) ? " - " + Html.SafeRaw(Model.ClientInfo.User.AppUserId) : string.Empty);

        }

        @if (LoggedUserIdentity.Current.IsUsersEnabled)
        {
            <a class="extended-info-app-user-id long-text" title="@appUserIdHeader">
                @appUserIdHeader
                <i class="appsee-icon_search"></i>
            </a>
        }
        else
        {
            <span class="extended-info-app-user-id" title="@appUserIdHeader">@appUserIdHeader</span>
        }

    </div>
}

我如何尝试使用这些助手的示例(Views / Sessions / ExtendedInfo-Web.cshtml):

@using Newtonsoft.Json
@using Shift6.Model.Extensions
@using Shift6.Web.Extensions
@model Shift6.Dashboard.viewmodels.Sessions.SessionInfoviewmodel


@ExtendedInfoHtmlHelpers.Title(Model)

<div id="sessions-extended-bottom-grid">

    <div id="sessions-extended-client-info" session-id="@Model.SessionId">

        @ExtendedInfoHtmlHelpers.SharedClientInfoLines(Model)

        <div class="client-info-line platform-info">
            @if (Model.ClientInfo.browserType != null)
            {
                <div class='browser-details'></div>
            }
        </div>

        @ExtendedInfoHtmlHelpers.Tags(Model)
    </div>

    @ExtendedInfoHtmlHelpers.SessionTimeline(Model)

    @ExtendedInfoHtmlHelpers.SessionExtras(Model)
</div>

在这些剃刀文件上的“构建操作”设置为“内容”。

我尝试添加

@using Shift6.Dashboard.App_Code.ExtendedInfoHtmlHelpers

到每个视图的开始,但是我得到:

A 'using namespace' directive can only be applied to namespaces; 'ExtendedInfoHtmlHelpers' is a type not a namespace. Consider a 'using static' directive instead
The type or namespace name 'ExtendedInfoHtmlHelpers' Could not be found (are you missing a using directive or an assembly reference?)

还尝试添加

@using Shift6.Dashboard.App_Code

到每个视图的开始,但是我得到:

An object reference is required for the non-static field,method,or property 'ExtendedInfoHtmlHelpers.Title(SessionInfoviewmodel)'

任何帮助将不胜感激。如果无法做到这一点,我很想听听您的意见是我的选择:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)