[RESOLVED] The name "Exclude" does not exist in current context
Hi,
Why am I receiving the error: The name "Exclude" does not exist in current context when using the following code?
asp Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
namespace MvcMusicStore.Models
{
[MetadataType(typeof(AlbumMetaData))]
public partial class Album
{
//Validation rules for Album class
[Bind(Exclude == "AlbumID")]
public class AlbumMetaData
{
[ScaffoldColumn(false)]
public object AlbumId {get; set;}
[DisplayName("Genre")]
public object GenreId { get; set; }
[DisplayName("Artist")]
public object ArtistId { get; set; }
[Required(ErrorMessage = "An album title is required")]
[StringLength(160)]
public object Title { get; set; }
[DisplayName("Album Art URL")]
[StringLength(1024)]
public object AlbumArtURL { get; set; }
[Required(ErrorMessage = "Price is required")]
[Range(0.01, 100.00, ErrorMessage = "Price must be between 0.01 and 100.00")]
public object Price { get; set; }
}
}
}
Thanks,
Nightwalker
Re: The name "Exclude" does not exist in current context
Eh, I haven't tried this in VS2010, but are you sure the syntax is
Code:
[Bind(Exclude == "AlbumID")]
and not
Code:
[Bind(Exclude = "AlbumID")]
?
.
Re: The name "Exclude" does not exist in current context
== is a comparison equals, while = is the assignment operator... but since you're in an attribute markup, I'm not sure C# rules apply....
And this thread would seem to back that up...
http://stackoverflow.com/questions/6...lude-id-in-mvc
-tg
Re: The name "Exclude" does not exist in current context
Quote:
Originally Posted by
honeybee
Eh, I haven't tried this in VS2010, but are you sure the syntax is
Thanks, for pointing out the oversight! Checking my notes again it is "=" and not "==" I am suppose to use.
Re: The name "Exclude" does not exist in current context
Quote:
Originally Posted by
techgnome
== is a comparison equals, while = is the assignment operator... but since you're in an attribute markup, I'm not sure C# rules apply....
C# rules do apply, the value "AlbumID" is being assigned to the property "Exclude" on the Bind attribute.