I have added a key-value pair in the action result like this:
[HttpPost, Authorize] public ActionResult ListFacilities(int countryid) { ... ModelState.AddModelError("Error","No facilities reported in this country!"); ... }
I have some cumbersome codes like these in a unit test to :
public void ShowFailforFacilities() { //bogus data var facilities = controller.ListFacilities(1) as PartialViewResult; Assert.AreSame("No facilities reported in this country!", facilities.ViewData.ModelState["Error"].Errors.FirstOrDefault().ErrorMessage); }
Of course, it works whenever I have only one error.
I don't like facilities.ViewData.ModelState["Error"].Errors.FirstOrDefault().ErrorMessage
.
Is there an easier way for me to fetch the value from that dictionary?