I have a page which list all Countries in a tabular form and view has a model like below:
@model IEnumerable<Country>
On the same page I have a link that allows the user to create a new Country via a modal popup(defined within that page)
<a operation="add" id="btnNewCountry" data-toggle="modal" data-target="#myModal" href="#">Add New Country</a>
Model popup snippet looks like below:
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
@using (Html.BeginForm("ManageCountry", "Admin", FormMethod.Post, new { enctype ="multipart/form-data" }))
{
<label for="module-text">Country Name</label>
<input type="text" id="txtName" name="name" />
<button type="submit" class="btn btn-primary">Save changes</button>
}
As soon as the user presses submit button, the control quickly reaches the Controller Action.
Now the challenge is I am not able to figure out how to apply Client Side validation on the CountryName textbox (something like @Html.ValidationMessagefor and Required) on the "Add New Country" Popup as the modal of the page( which is IEnumerable) is different from the Modal Popup (which works only on a single Country Object)
Please help!!