Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将Razor转换为ASPX时我做错了什么?_C#_Asp.net Mvc_Razor - Fatal编程技术网

C# 将Razor转换为ASPX时我做错了什么?

C# 将Razor转换为ASPX时我做错了什么?,c#,asp.net-mvc,razor,C#,Asp.net Mvc,Razor,我正在为MVC做一个简单的(我认为)教程。唯一的问题是教程使用了Razor,我需要使用ASPX。我正在找的工作就是用它 我花了几个小时在互联网上寻找可能性,但我仍然得到这个错误: 编译错误 描述:编译所需的资源时出错 为这个请求提供服务。请检查以下内容 具体错误详细信息,并适当修改源代码。 编译器错误消息:CS1061:“对象”不包含定义 对于“Name”,没有接受第一个参数的扩展方法“Name” 找不到类型为“object”的(是否缺少using指令或 程序集引用?)源错误: 第12行: 第1

我正在为MVC做一个简单的(我认为)教程。唯一的问题是教程使用了
Razor
,我需要使用
ASPX
。我正在找的工作就是用它

我花了几个小时在互联网上寻找可能性,但我仍然得到这个错误:

编译错误

描述:编译所需的资源时出错 为这个请求提供服务。请检查以下内容 具体错误详细信息,并适当修改源代码。
编译器错误消息:CS1061:“对象”不包含定义 对于“Name”,没有接受第一个参数的扩展方法“Name” 找不到类型为“object”的(是否缺少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();
        }
    }
}
%@ 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是:

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();
        }
    }
}
%@ 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>
%@Page Language=“C#”MasterPageFile=“~/Views/Shared/Site.Master”Inherits=“System.Web.Mvc.ViewPage”%%>
.

餐厅: 评级:
如果要使用强类型视图,必须在此行中定义页面的
视图模型

Inherits="System.Web.Mvc.ViewPage<TheViewModel>" %>
Inherits=“System.Web.Mvc.ViewPage”%>
因此,在你的情况下,它应该是

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


如果您没有像以前那样指定任何内容,
ViewModel
将是对象,并且正如您所知,它没有
Name
Rating
属性。

我相信您不希望冒号作为脚本分隔符的一部分:

<h2><% ViewBag.Message %></h2>

您缺少
我只阅读了问题标题,但听起来像是所有内容。我们在哪里可以找到教程?冒号指定脚本分隔符的输出应为HTML编码