c# - कस्टम विशेषता नल संदर्भ अपवाद
asp.net-mvc asp.net-mvc-5 (0)
मेरे पास एक दृश्य मॉडल है I
public class fooViewModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
[CustomAttribute]
public float foo1{ get; set; }
[Required]
[CustomAttribute]
public decimal foo2 { get; set; }
}
मैंने एक कस्टम सर्वर साइड सत्यापन विशेषता बनाई है।
[AttributeUsage(AttributeTargets.Property)]
public class CustomAttribute : RequiredAttribute
{
public CustomAttribute()
{
ErrorMessage = "Some message";
}
public override bool IsValid(object value)
{
string input = value.ToString();
//some validation logic
return result;
}
}
समस्या यह है कि मेरा मान पैरामीटर कभी-कभी नल होता है, लेकिन मुझे पता नहीं क्यों