0

我得到的错误是:

找不到类型或命名空间名称“LastSundayDate”(您是否缺少 using 指令或程序集引用?)

这是我的视图代码:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Report/Report.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<LastSundayDate>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
   Trade Searches Data
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>TradeUK KPI Searches Data</h2>
<p></p>

然后我有:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TradeUK.Entities.Reporting
 {
   public class LastSundayDate
   {
       public virtual int Title { get; set; }
       public virtual int Total { get; set; }
       public virtual int Week6 { get; set; }
       public virtual int Week5 { get; set; }
        public virtual int Week4 { get; set; }
        public virtual int Week3 { get; set; }
       public virtual int Week2 { get; set; }
        public virtual int Week1 { get; set; }
   }
 }

在我的控制器中,我有:

public ActionResult TradeUKKPIShowData(DateTime date) //show actual data in the view
{
  var reportData = _reportingService.GetTradeUKKPISearches(date);
  return View(reportData);
}
4

1 回答 1

2

包括你的类的命名空间。否则你的程序无法理解这个LastSundayDate类在哪里。

改变

Inherits="System.Web.Mvc.ViewPage<IEnumerable<LastSundayDate>>

Inherits="System.Web.Mvc.ViewPage<IEnumerable<
                                     TradeUK.Entities.Reporting.LastSundayDate>>

或者,您也可以将命名空间导入视图。在您的视图中添加这一行,在Page指令声明上方

<%@ Import Namespace="TradeUK.Entities.Reporting" %>

现在您不需要为该类添加完整的命名空间,您可以简单地在您的视图中访问该类。您问题中的代码可以正常工作。

If this class is defined in a Project other than your current UI project, you need to add a reference to that project under the References section

于 2012-08-13T13:42:10.507 回答