[英]Unable to display view page using ASP.NET MVC2
尝试使用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>
人.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
运行时,出现上述错误。请帮助我解决此错误。
Test3是与您执行的项目分开的项目吗? 如果是这种情况,请检查您的项目装配链接并验证所有涉及的项目的目标框架都相同,以解决此问题。 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.