PDA

Click to See Complete Forum and Search --> : VS 2010 [RESOLVED] The name "Exclude" does not exist in current context


Nightwalker83
Jun 24th, 2011, 03:29 AM
Hi,

Why am I receiving the error: The name "Exclude" does not exist in current context when using the following 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

honeybee
Jun 24th, 2011, 04:20 AM
Eh, I haven't tried this in VS2010, but are you sure the syntax is

[Bind(Exclude == "AlbumID")]

and not

[Bind(Exclude = "AlbumID")]


?

.

techgnome
Jun 24th, 2011, 07:18 AM
== 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/685561/how-to-exclude-another-attribute-in-this-syntext-bindexclude-id-in-mvc

-tg

Nightwalker83
Jun 24th, 2011, 06:43 PM
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.

Evil_Giraffe
Jun 30th, 2011, 07:42 PM
== 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.