Duplicate keys in ModelState.Keys

bk18

New Member
Hi all I wonder if someone can help, as i've been scratching my head for hours on this one. I seem to be getting duplicate keys in my ModelState.Keys object. I have the following class:\[code\]public class MeetingRoomRequestViewModel{ public int MeetingRoomRequestId { get; set; } [Required(ErrorMessage = "Name is required")] [StringLength(250)] public string User { get; set; } [Required(ErrorMessage = "Email is required")] [StringLength(250)] public string UserEmail { get; set; } [StringLength(250)] [Required(ErrorMessage = "Request Title is required")] public string Title { get; set; } [AllowHtml] public string Comments { get; set; }}\[/code\]I'm using the TryUpdateModel method to validate on form submission and using the following code to return the error keys via JSON:\[code\]public Dictionary<string, object> GetErrorsFromModelState(){ var errors = new Dictionary<string, object>(); foreach (var key in ModelState.Keys) { // Only send the errors to the client. if (ModelState[key].Errors.Count > 0) { errors[key] = ModelState[key].Errors; } } return errors;}\[/code\]However when trying to debug why my errors don't seem to be coming through to the front-end html, I found that this is what is being returned and thus why the errors are not appearing on the html. However I don't understand why it seems to be returning the error keys twice??
3Mk3r.jpg
 
Back
Top