I have a ViewModel defined like this:
public class ProfileSnapshotViewModel
{
public Guid ProfileSnapshotId { get; set; }
[Required(AllowEmptyStrings = true)]
public string Salutation { get; set; }
//...
public bool IsActive { get; set; }
}
And my MVC is set like this:
<td class="Cell">
@Html.HiddenFor(model => model.ProfileSnapshotId)
@Html.HiddenFor(model => model.IsActive)
@Html.HiddenFor(model => model.Salutation)
//...
When I set up the model I set it up like this:
return PartialView("_additionalreviewerrow",
new ProfileSnapshotViewModel
{
IsActive = true,
Salutation = ""
});
However, my ModelState.IsValid continues to be false when submitting, saying 'Salutation is required'.
What can I do to ensure the HiddenFor is holding the empty string, and validation doesn't complain?
(This is part of a larger chunk of code, so if you think something else could be affecting it, please comment and I'll try to add it.)