I ran into a problem, and I hope you can help me solve it.
I have a form with several fields in it, few of them validated remotely.
@using (Html.BeginForm("Action", "Controller", new { id = "myForm" }))
{
@Html.AntiForgeryToken()
<table>
<tr>
<td width="225">Work permit/Registration card:</td>
<td>Start date: @Html.EditorFor(m => m.WorkPermitStart)</td>
<td width="50"></td>
<td>End date: @Html.EditorFor(m => m.WorkPermitEnd)</td>
<td>@Html.ValidationMessageFor(m => m.WorkPermitEnd)</td>
</tr>
</table>
<li><button type="submit" value="submit" class="form-yes">submit</button></li>
}
piece of code like this works just fine, when WorkPermitEnd input loses focus the remote validation is done, and in case the fields are invalid, the message is shown in the following table cell as expected.
My problem is, I need to change it and put the validation message outside the form itself, in completely different section. And this is where I struggle to find a suitable solution, as when losing formcontext, the
@Html.ValidationMessageFor(m => m.WorkPermitEnd)
just won't work and doesn't show the validation message for the input, that is in the original form. So my question is, is there some way to pass the validation message to different section on the page?
EDIT: added layout of the page
<section id="content">
@RenderBody()
</section>
<aside id="messages">
<aside id="validation">
@RenderSection("ValidateMessage", required: false)
</aside>
<aside id="help">
@RenderSection("Help", required: false)
</aside>
</aside>