I have a nullable field in a viewmodel that I'm using a DropDownListFor to allow for selection and would like to add validation that only allows the user to submit the form if they select a different option from the drop down than what they already have stored. It's valid for the user to have a null value stored as their service provider so its not a required field, I just don't want anyone to be able to submit the value they already have. Is a custom validation attribute the way to go here?

public class ServiceProviderViewModel
    public Guid? SelectedServiceProvider { get; set; }

    public IEnumerable<SelectListItem> ServiceProviderList { get; set; }


@Html.DropDownListFor(model => model.SelectedServiceProvider, Model.ServiceProviderList, "None", new { @class = "form-control"})

Related posts

Recent Viewed