I have a view with two forms each containing their own
@Html.ValidationSummary()
When the page is loaded, a querystring parameter is checked and if it exists I call:
ModelState.AddModelError("", "Querystring error");
However, this results in the error message appearing in both @Html.ValidationSummary() even if I specify a property in the form model.
I have a work around which is to have a seperate error message property in the model for the form and populate that and then display it if it exists in a label, but wondered if it is possible to specify one individual @Html.ValidationSummary() within a form to allow me to use ModelState.AddModelError?
ValidationSummaryis per model, not per an HTML form. If you effectively have two models on the page with two validation summaries, look into using partial views.ModelState.AddModelErroris only affecting one of the models when using partial views? When the page loads it checks the query string, callsModelState.AddModelErrorif it is not correct, then returns the View passing in the model which contains 2 classes i.e. the models for each form. I'm not sure how using a Partial View would resolve my problem at the moment.