Hi I have the following cod throughout my app but with just two fields it's not working.
[Required]
public string DevelopmentPM { get; set; }
The following test runs and passes:
[TestMethod]
public void SiteConstruction_MODEL_DevelopmentPM_Is_Required()
{
//arrange
var propertyInfo = typeof(SiteConstructionMetadata).GetProperty
("DevelopmentPM");
//act
var attribute = propertyInfo.GetCustomAttributes(typeof(RequiredAttribute),
true).Cast<RequiredAttribute>().FirstOrDefault();
//assert
Assert.IsNotNull(attribute);
}
My controlller looks like:
TryUpdateModel(siteConstruction);
if (!ModelState.IsValid)
return View(siteConstruction);
I have other required fields in model and they are OK. This field is null (I checked) but doesn't make the model invalid - so no validation and an error on save.
My View
<li>
<label for="DevelopmentPM">
<strong>Development PM:</strong></label>
<%= Html.TextBox("DevelopmentPM") %>
<%= Html.ValidationMessage("DevelopmentPM", "*") %>
</li>
I've looked at my .dbml (Linq to SQl), spelling looks ok.
I'm I missing something simple - please, going mad.
Thanks
Davy