i am doing a simple (I think) tutorial for MVC. The only issue is the tutorial uses Razor and I need to use ASPX. Job I’m looking at uses it.
I have spent hours looking over the internet for possibilities but I am still getting this error:
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:
The controller code is:
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();
}
}
}
The ASPX is:
%@ 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>
If you want to use strongly typed views You have to define the
View Modelof the page in this line:So in your case it should be;
If you don’t specify anything as you did, The
ViewModelwill be object, and as you well know, it doesn’t haveNameorRatingproperties.