Album Editor Failed

Aug 2, 2010 at 6:54 PM
Edited Aug 2, 2010 at 7:02 PM

I´m following the tutorial on the page 54, where the create a Album Editor.

I following all pages on tutorial again, to create a Editor Album, but always show no DropDownList to Genres and Artistis. Always show us TextBox to edit.

It seems to me that the page Album.ascx is not accessed. If yes, why?
What can be?

I use VS2010 Ultimate.

Well, i paste my code now.

StoreManagerViewModel.cs. On the folder ViewModels

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcMusicStore.Models;

namespace MvcMusicStore.ViewModel
{
    public class StoreManagerViewModel
    {
        public Album Album { get; set; }
        public List<Artist> Artists { get; set; }
        public List<Genre> Genres { get; set; }
    }
}

StoreManagerController.cs. On the folder Controllers

        public ActionResult Edit(int id)
        {
            var viewModel = new StoreManagerViewModel()
            {
                Album = storeDB.Albums.Single(a => a.AlbumId == id),
                Genres = storeDB.Genres.ToList(),
                Artists = storeDB.Artists.ToList()
            };

            return View(viewModel);
        }


Edit.aspx. On the folder ~\Views\StoreManager

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

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Edit -
    <%: Model.Album.Title %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <form id="form1" runat="server">
    <h2>
        [ Edit ]
    </h2>
    <% using (Html.BeginForm())
       {%>
    <%: Html.ValidationSummary(true) %>
    <fieldset>
        <legend>Edit Album</legend>
        <%: Html.EditorFor(model => model.Album, new { Artists = Model.Artists, Genres = Model.Genres })%>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
    <% } %>
    <div>
        <%: Html.ActionLink("Back to List", "Index") %>
    </div>
    </form>
</asp:Content>


Album.ascx. On the folder ~\Views\Shared\EditorTemplate
<%@ Import Namespace="MvcMusicStore" %>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcMusicStore.Models.Album>" %>
<p>
    <%: Html.LabelFor(model => model.Title)%>
    <%: Html.TextBoxFor(model => model.Title)%>
    <%: Html.ValidationMessageFor(model => model.Title)%>
</p>
<p>
    <%: Html.LabelFor(model => model.Price)%>
    <%: Html.TextBoxFor(model => model.Price)%>
    <%: Html.ValidationMessageFor(model => model.Price)%>
</p>
<p>
    <%: Html.LabelFor(model => model.AlbumArtUrl)%>
    <%: Html.TextBoxFor(model => model.AlbumArtUrl)%>
    <%: Html.ValidationMessageFor(model => model.AlbumArtUrl)%>
</p>
<p>
    <%: Html.LabelFor(model => model.Artist)%>
    <%: Html.DropDownList("ArtistId", new SelectList(ViewData["Artists"] as IEnumerable, "ArtistId", "Name", Model.ArtistId))%>
</p>
<p>
    <%: Html.LabelFor(model => model.Genre)%>
    <%: Html.DropDownList("GenreId", new SelectList(ViewData["Genres"] as IEnumerable, "GenreId", "Name", Model.GenreId))%>
</p>

Aug 2, 2010 at 7:18 PM
Edited Aug 2, 2010 at 8:21 PM

Hello, in the Edit.aspx file you are creating 2 forms, this is the first:

 

<form id="form1" runat="server">

 

and the other one is here:

 

<% using (Html.BeginForm())
{%>

 

Maybe this is the problem you are having. I had this problem too, and made the validation failed.

Aug 6, 2010 at 1:15 AM

Good!! I found the problem.

The change the nome of the folder EditorTemplate to EditorTemplates. And works!!

I was surprise because there is no mention of this name anywhere in the project.

 

Coordinator
Aug 9, 2010 at 8:22 AM

@fabiocolli - Glad you got it fixed. The text and screenshots at the top of page 51 show the name EditorTeamplates. Was there something unclear about that?