I have a page that calls a partialview formed by a div with text field into it, through a button. Each time the button is pressed a line is added. The problem is that I can not validate the empty fields of this partialview.
I use @Html.ValidationMessageFor
My View
@model CondicaoPagamentoDiasViewModel
@using (Html.BeginCollectionItem("CondicaoPagamentoDiass"))
{
<div class="form-group">
@Html.HiddenFor(model => model.CondicaoPagamentoDiasId)
<label class="col-md-1 control-label"></label>
<div class="col-md-10">
<div class="col-md-1">
@Html.EditorFor(model => model.Dias, new { htmlAttributes = new { @class = "form-control prazo" } })
@Html.ValidationMessageFor(model => model.Dias, "", new { @class = "text-danger" })
</div>
<div class="col-md-2">
<img src="@Url.Content("~/Content/img/excluir.png")" onclick="$(this).parent().parent().parent().remove();" style="cursor:pointer;">
</div>
</div>
</div>
}
@{ Html.RenderPartial("_ValidationMaskPartial"); }
My PartialView
<div style="margin: 0 0 0 102px;" id="condicoes-pagamento" name="condicoes-pagamento">
@if (Model != null)
{
foreach (var condicoesPgto in Model.CondicaoPagamentoDiass)
{
@Html.Partial("_CondicoesPagamentoDia", condicoesPgto);
}
}
</div>
I call it here. I just want to validate her fields as you have on the main page.