“AppHelper”这个名称在当前上下文中不存在

时间:2010-04-29 13:48:27

标签: asp.net-mvc

当它发出错误说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 个答案:

答案 0 :(得分:0)

尝试

<%=DocuvaultMVC.Helpers.AppHelper.PDFUrl(ViewData.Model.DocumentId,i)%>

答案 1 :(得分:0)

是的 - 你需要引用帮助器,所以它类似于:

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

在你的视图顶部。或者,您可以将它放在web.config中。