Click here to Skip to main content
15,913,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello fellas,

I am following the MvcMusicStore tutorial from ASP.NET and so far so good, except I am having some issues with the Album Covers not updating. basically, there is a Store page with a Music List table. This table has edit, delete, and details options. When you "edit" it takes you to a form where you can add an Album URL. This album URL should be passed to another view where all the music albums are displayed. (to include the index page where the top 5 albums are also displayed)

This is how it is structured

Controller Edit GET and POST portions
C#
// GET: /StoreManager/Edit/5

        public ActionResult Edit(int id)
        {
            Album album = db.Albums.Find(id);
            ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
            ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId);
            return View(album);
        }

        //
        // POST: /StoreManager/Edit/5

        [HttpPost]
        public ActionResult Edit(int Id, Album album)
        {
            if (ModelState.IsValid)
            {
                album.AlbumId = Id;
                db.Entry(album).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
            ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId);
            return View(album);
        }


This is the Edit View

C#
@model WebsiteManager.Models.Album

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Album</legend>

        @Html.HiddenFor(model => model.AlbumId)

        <div class="editor-label">
            @Html.LabelFor(model => model.GenreId, "Genre")
        </div>
        <div class="editor-field">
            @Html.DropDownList("GenreId", String.Empty)
            @Html.ValidationMessageFor(model => model.GenreId)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ArtistId, "Artist")
        </div>
        <div class="editor-field">
            @Html.DropDownList("ArtistId", String.Empty)
            @Html.ValidationMessageFor(model => model.ArtistId)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Title)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Title)
            @Html.ValidationMessageFor(model => model.Title)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Price)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Price)
            @Html.ValidationMessageFor(model => model.Price)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.AlbumArtUrl)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.AlbumArtUrl)
            @Html.ValidationMessageFor(model => model.AlbumArtUrl)
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}


This is the Detail View. Supposedly, if the field being viewed had an album cover included, it should show here. So far all it is passed is the URL of the cover album itself, not the image.

C#
@model WebsiteManager.Models.Album

@{
    ViewBag.Title = "Details";
}

<h2>Details</h2>

<fieldset>
    <legend>Album</legend>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Genre.Name)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Genre.Name)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Artist.Name)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Artist.Name)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Title)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Title)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Price)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Price)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.AlbumArtUrl)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.AlbumArtUrl)
    </div>
</fieldset>
<p>
    @Html.ActionLink("Edit", "Edit", new { id=Model.AlbumId }) |
    @Html.ActionLink("Back to List", "Index")
</p>


The Album class in case it is of any help

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace WebsiteManager.Models
{
    [Bind(Exclude = "AlbumId")]
    public class Album
    {
        [ScaffoldColumn(false)]
        public int AlbumId { get; set; }
        [DisplayName("Genre")]
        public int GenreId { get; set; }
        [DisplayName("Artist")]
        public int ArtistId { get; set; }
        [Required(ErrorMessage = "An Album Title is required")]
        [StringLength(160)]
        public string Title { get; set; }
        [Required(ErrorMessage = "Price is required")]
        [Range(0.01, 100.00,
            ErrorMessage = "Price must be between 0.01 and 100.00")]
        public decimal Price { get; set; }
        [DisplayName("Album Art URL")]
        [StringLength(1024)]
        public string AlbumArtUrl { get; set; }
        public virtual Genre Genre { get; set; }
        public virtual Artist Artist { get; set; }
        public virtual List<OrderDetail> OrderDetails { get; set; }
    }
}


And finally the index form where it shows the call to the top 5 album images

C#
<div id="promotion"></div><br />
<h3>Fresh off the grill</h3>

<ul id="album-list">
    @foreach (var album in Model)
    {
        <li><a href="@Url.Action("Details", "Store", new { id = album.AlbumId })"><img alt="@album.Title" src="@album.AlbumArtUrl" /> <span>@album.Title</span></a></li>
    }
</ul>


I appreciate any help. ME and another engineer have been brainstorming but nothing yet.

if you want to see the site live and test it go to

djfitz.azurewebsites.net

thanks
Posted

1 solution

As we discussed about the update issue before and it is now solved.

But again there was an issue on display of image as per the question.
So, I just visited your website and played with it.

When I viewed the html source of the pages where Album and its details are displaying, I found that the updated image Url is added to the image tag, but it is failed to load that image due to incorrect path.

Then I just updated one online image to one of the Album cover and then checked it.
It is working.

So, please check the Urls you are updating for the Album covers, whether they are correct or not.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900