【发布时间】:2012-02-04 23:57:29
【问题描述】:
我正在为 MVC 做一个简单的(我认为)教程。唯一的问题是教程使用Razor,我需要使用ASPX。我正在寻找的工作使用它。
我花了几个小时在互联网上寻找可能性,但我仍然收到此错误:
编译错误
描述:编译所需资源时出错 服务这个请求。请查看以下内容 具体错误详情并适当修改您的源代码。
编译器错误消息:CS1061:“对象”不包含定义 对于“名称”并且没有扩展方法“名称”接受第一个参数 可以找到“对象”类型的(您是否缺少 using 指令或 程序集引用?)源错误:第 12 行:
第 13 行:
第 14 行:餐厅:
第 15 行:评级:
第 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 页面的开头缺少
<,但这可能是复制粘贴问题。请参阅下面的答案。 -
我只看了问题的标题,但听起来什么都有。
-
在哪里可以找到教程?
标签: c# asp.net-mvc razor