代码之家  ›  专栏  ›  技术社区  ›  Pinu

当前上下文中不存在名称“apphelper”

  •  0
  • Pinu  · 技术社区  · 14 年前

    当它给出一个错误说AppHelper不存在时,我是否缺少任何引用?

    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewPage<DocumentsController.ViewDetails>" %>
    <%@ Import Namespace="DocuvaultMVC.Controllers" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
        Document View
    </asp:Content>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
        <h2>Notes</h2>
          <% Html.RenderPartial("~/Views/Shared/UserControl/Notes.ascx",Model.Notes); %>
        <br />
        <h2>User Tracking Informtaion</h2>
           <% Html.RenderPartial("~/Views/Shared/UserControl/Tracking.ascx",Model.Log); %>
          <div>
           <% for (int i = 1; i <= ViewData.Model.Pages; i++)
              { %>
              <br />
              <img src="<%=AppHelper.PDFUrl(ViewData.Model.DocumentId,i)%>" alt="Document" width="612" height="792" />
           <%}%>
           <div>
           </div>
           </div>
    </asp:Content>  
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data;
    
    
        namespace DocuvaultMVC.Helpers
        {
            public static class AppHelper
            {
                /// <summary>
                /// Builds a Script url
                /// </summary>
                /// <param name="cssFile">The name of the CSS file</param>
                public static string ScriptUrl(string script)
                {
                    return VirtualPathUtility.ToAbsolute("~/scripts/" + script);
                }
    
            public static string PDFUrl(int id, int page)
            {
                return VirtualPathUtility.ToAbsolute("~/Documents/ViewDocument.aspx/" + id + "/" + page);
            }
        }
    }
    
    2 回复  |  直到 14 年前
        1
  •  0
  •   Richard Friend    14 年前

    尝试

    <%=DocuvaultMVC.Helpers.AppHelper.PDFUrl(ViewData.Model.DocumentId,i)%>
    
        2
  •  0
  •   lancscoder    14 年前

    是的-您需要引用助手,因此它类似于:

    <%@ Import Namespace="DocuvaultMVC.Helpers" %>
    

    在你的上方。或者,您可以将其放到web.config中。