Hi all,
I feel like a complete idiot asking this but on page 244 (Chapter 5: Controllers) I can't get the code to work correctly. I am a complete beginner to MVC but have been using ASP and Webforms for years.
The book says:
Quote:
|
"Define a simple class here named Product"
|
. Um, where are we currently? Never mind, I have created the Product class in a folder in the root called 'Objects' for now.
The book then goes on to describe the Controller and View. I have the view but the texboxes are not populating with the product instance. What have I done wrong? (When I created the View I did not create a strongly typed view)
My view code is:
HTML Code:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Product>" %>
<%@ Import Namespace="MVC_App_WroxChapter3.Objects"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<title>Edit</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Edit</h2>
<p><%= Html.Encode(ViewData["Message"]) %></p>
<% using (Html.BeginForm())
{ %>
<p>Name: <%= Html.TextBox("ProductName") %> <%= Html.ValidationMessage("ProductName") %>
</p>
<p>Price: £ <%= Html.TextBox("UnitPrice") %> <%= Html.ValidationMessage("UnitPrice") %>
</p>
<input type="submit" />
<% } %>
</asp:Content>
Edit:
OK so if I return the view as such:
HTML Code:
return View(product);
then the form fields are completed.
But what is
HTML Code:
ViewData["product"] = product;
supposed to do?
Thanks,
Noob!