Question

In DinnerController I got a data.enter image description here

 public ActionResult Details(int id)
 {

            Dinner dinner = dinnerRepository.GetDinner(id);

            if (dinner == null)
                return View("NotFound");
            else
                return View("Details", dinner);
  } 

and in details.aspx I bound it like this.

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Details</h2>
    <fieldset>
        <legend>Fields</legend>
        <p>
            DinnerID:
            <%= Html.Encode(Model.DinnerID) %>
        </p>
        </fieldset>
</asp:Content>

but I got a error.

Compiler Error Message: CS1061: 'object' does not contain a definition for 'DinnerID' and no extension method 'DinnerID' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?).

I just start to learn mvc and unable to understand the problem.May I missing something.Plz help?

Was it helpful?

Solution 2

I forget to check the check box Create a strongly-typed view when create a view show i got this error.i solve this through adding <HelloMvc.Models.Dinner> in details.aspx page. Means when I got error code like this.

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

After solve the problem code becames:

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

Thanks for reply.I post this ans for future ref.

OTHER TIPS

You are doing several things wrong :
1) It is called MVC meaning Model View Controller( your Dinner entity is passed to your view through your controller )
What you are trying to make is a new View . It will be Created in the View section of your project.

I think this code might show you what you need :

@model HelloMvc.Models.Dinner  //passing the value of dinner is done here . from now on you will refer to the dinner object with Model
<table>
       <tr>
         <td>
           Description
         </td>
         <td>
            @Html.Display(Model.Description) //google other @Html diplay modes ( Label Textbox, etc)
         </td>
       </tr>
</table>

MVC can be hard at first especially if you developed a Asp.Net thinking; be patient and understand the basic concepts at first and you will love it.
Here's a link that will help you understand the entire process.
http://geekswithblogs.net/dotNETvinz/archive/2011/06/03/asp.net-mvc-3-creating-a-simple-sign-up-form.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top