Problem with Bind Exclude on Album model class

Apr 25, 2011 at 4:10 PM

I think there could be a problem with the Bind annotation on the Album class.  I'm pretty new to MVC, so am not totally sure about this.

My understanding is that the [Bind(Exclude = "AlbumId")] attribute means that when an action method takes a parameter of type Album, then the AlbumId post variable from the client will not be bound to the model.

This causes a problem when editing an album, and I get an exception every time.  This is because AlbumId of the passed in Album is still 0.

Is this just me or is everyone else having the same problem?  Why is the Bind attribute placed on the Album class?

Oct 15, 2013 at 2:49 PM
So, How did you solve it, didn't you?
Because I've found this problem also.
Oct 15, 2013 at 10:40 PM
Didn't really look at it too much, but everything seems to work if you simply remove the Bind attribute from the Album class, like this ...
diff --git a/MvcMusicStore/Models/Album.cs b/MvcMusicStore/Models/Album.cs
index 1d0e4e7..15fb11b 100644
--- a/MvcMusicStore/Models/Album.cs
+++ b/MvcMusicStore/Models/Album.cs
@@ -5,7 +5,6 @@ using System.Collections.Generic;

 namespace MvcMusicStore.Models
 {
-    [Bind(Exclude = "AlbumId")]
     public class Album
     {
         [ScaffoldColumn(false)]