Strange issue with ASP.NET MVC3 client side validation
I am having an issue with ASP.NET MVC3 client side validation.
My view is based on a viewmodel I've created with the following fields as Required
public class AppointmentFeedbackViewModel_Validation
{
[Required]
public string AttendeeName { get; set; }
[Required(ErrorMessage = "Notes must be filled in")]
public string Notes { get; set; }
[Required(ErrorMessage = "Appointment status must be filled in")]
public int AppointmentStatusId { get; set; }
[Required]
public int StarId { get; set; }
}
Unfortunately, a completely unrelated field SubStatusId
appears as required on submitting the form.
Th开发者_JS百科is drop down list is passed an empty List
from the controller
new List<EF.ViewModels.OpportunityConnectTypeViewModel>();
and marked up as below
<div class="display-label-styled">
Please select another reason for this outcome
</div>
<div class="display-field-styled">
@Html.DropDownListFor(model => model.SubStatusId, new SelectList(ViewBag.SubStatus, "ID", "StatusName"))
@Html.ValidationMessageFor(model => model.SubStatusId)
</div>
If anybody can shed any light on this for me, I'd really appreciate it.
Is SubStatusId an int? Int's are implicitly required. If you want it to not be required, declare it as a nullable int:
public int? SubStatusId;
精彩评论