簡體   English   中英

使用ASP.NET MVC2無法顯示視圖頁面

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM