无法使用ASP.NET MVC2显示视图页面

时间:2015-06-20 07:03:56

标签: c# asp.net visual-studio-2010

尝试使用ASP.NET MVC2在视图页面中显示数据时出现以下错误。

  

错误:

Server Error in '/' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0234: The type or namespace name 'Person' does not exist in the namespace 'Test3.Models' (are you missing an assembly reference?)

Source Error:


Line 170:    
Line 171:    [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
Line 172:    public class views_home_index_aspx : System.Web.Mvc.ViewPage<Test3.Models.Person>, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler {
Line 173:        
Line 174:        private static bool @__initialized;

Source File: c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\86f20dd8\a41e18c\App_Web_index.aspx.a8d08dba.z89z2bzv.0.cs    Line: 172 

我的代码文件如下。

  

的Index.aspx:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Test3.Models.Person>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%: ViewData["Message"] %></h2>
    <p><% Html.TextBoxFor(Model=> Model.Name); %>Html</p>
    <p>
        To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
    </p>
</asp:Content>
  

Person.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Test3.Models
{
    public class Person
    {
        public string Name { get; set; };
    }
}
  

HomeController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Test3.Models;
namespace Test3.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";
            Person p = new Person();
            p.Name = "subhrajyoti";

            return View(p);
        }

        public ActionResult About()
        {
            return View();
        }
    }
}

当我使用ctrl+f5运行时,我收到了上述错误。请帮我解决此错误。

1 个答案:

答案 0 :(得分:0)

Test3是否与您执行的项目分开?如果是这种情况,请检查项目程序集链接并验证所涉及的所有项目的目标框架是否相同以解决此问题。希望它有所帮助。