我正在爲MVC做一個簡單的(我認爲)的教程。唯一的問題是教程使用Razor
,我需要使用ASPX
。我正在看的工作使用它。我在做什麼錯誤將Razor轉換爲ASPX?
我花了幾個小時尋找在互聯網上的可能性,但我仍然得到這個錯誤:
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: CS1061: 'object' does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) Source Error:Line 12:
Line 13:
Line 14: Restaurant: <%: Model.Name %>
Line 15: Rating: <%: Model.Rating %>
Line 16:
控制器代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EdeToFood.Models;
namespace EdeToFood.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
var model = new RestaurantReview()
{
Name = "Tersiguil's",
Rating = 9
};
return View(model);
}
public ActionResult About()
{
ViewBag.Location = "Maryland, USA";
return View();
}
}
}
的ASPX是:
%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2><%: ViewBag.Message %></h2>
<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>
<div >
Restaurant: <%: Model.Name %>
Rating: <%: Model.Rating %>
</div>
</asp:Content>
你缺少'<'在aspx頁面的開始,但它可能是一個複製粘貼問題。請參閱下面的答案。 – gdoron 2012-02-05 00:14:34
我只讀了問題標題,但聽起來像是一切。 – smartcaveman 2012-06-06 17:45:09
我們在哪裏可以找到教程? – SamekaTV 2014-01-07 10:32:13