Hi,

I keep receiving "Object reference not set to an instance of the object" when trying to run a form. This is the code I am using:

asp Code:
  1. <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcMusicStore.Models.Album>" %>
  2.  
  3. <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
  4.     Edit
  5. </asp:Content>
  6.  
  7. <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  8.  
  9.     <h2>Edit - <%: Model.Title%></h2>
  10.  
  11.     <% using (Html.BeginForm()) {%>
  12.         <%: Html.ValidationSummary(true) %>
  13.        
  14.         <fieldset>
  15.             <legend>Edit Album</legend>
  16.             <%Html.EditorForModel(); %>
  17.             <div class="editor-label">
  18.                 <%: Html.LabelFor(model => model.AlbumId) %>
  19.             </div>
  20.             <div class="editor-field">
  21.                 <%: Html.TextBoxFor(model => model.AlbumId) %>
  22.                 <%: Html.ValidationMessageFor(model => model.AlbumId) %>
  23.             </div>
  24.            
  25.             <div class="editor-label">
  26.                 <%: Html.LabelFor(model => model.GenreId) %>
  27.             </div>
  28.             <div class="editor-field">
  29.                 <%: Html.TextBoxFor(model => model.GenreId) %>
  30.                 <%: Html.ValidationMessageFor(model => model.GenreId) %>
  31.             </div>
  32.            
  33.             <div class="editor-label">
  34.                 <%: Html.LabelFor(model => model.ArtistId) %>
  35.             </div>
  36.             <div class="editor-field">
  37.                 <%: Html.TextBoxFor(model => model.ArtistId) %>
  38.                 <%: Html.ValidationMessageFor(model => model.ArtistId) %>
  39.             </div>
  40.            
  41.             <div class="editor-label">
  42.                 <%: Html.LabelFor(model => model.Title) %>
  43.             </div>
  44.             <div class="editor-field">
  45.                 <%: Html.TextBoxFor(model => model.Title) %>
  46.                 <%: Html.ValidationMessageFor(model => model.Title) %>
  47.             </div>
  48.            
  49.             <div class="editor-label">
  50.                 <%: Html.LabelFor(model => model.Price) %>
  51.             </div>
  52.             <div class="editor-field">
  53.                <%: Html.TextBoxFor(model => model.Price, String.Format("{0:F}", Model.Price)) %>
  54.                 <%: Html.ValidationMessageFor(model => model.Price) %>
  55.             </div>
  56.            
  57.             <div class="editor-label">
  58.                 <%: Html.LabelFor(model => model.AlbumArtUrl) %>
  59.             </div>
  60.             <div class="editor-field">
  61.                 <%: Html.TextBoxFor(model => model.AlbumArtUrl) %>
  62.                 <%: Html.ValidationMessageFor(model => model.AlbumArtUrl) %>
  63.             </div>
  64.            
  65.             <p>
  66.                 <input type="submit" value="Save" />
  67.             </p>
  68.         </fieldset>
  69.  
  70.     <% } %>
  71.  
  72.     <div>
  73.         <%: Html.ActionLink("Back to List", "Index") %>
  74.     </div>
  75.  
  76. </asp:Content>

It is complaining about model some reason and I can't figure out why.

The first error occurs on this line:

asp Code:
  1. <h2>Edit - <%: Model.Title%></h2>

However if I remove it the next error occurs on this line and so on:

asp Code:
  1. <%: Html.TextBoxFor(model => model.Price, String.Format("{0:F}", Model.Price)) %>

Have I missed a namespace somewhere?

Thanks,


Nightwalker