1
I have a page that calls a partialview formed by a div with text field inside it, through a button. Each time the button is pressed a line is added. The problem is that I cannot validate the empty fields of this partialview.
I use the @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"); }
Minha 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 her here. I just want to validate her fields like you have on the main page.
You want to validate the partial fields _Conditions of payment?
– Randrade
That’s right. I want to validate as in the main, in it I have an equal and it validates.
– jp_almeida
You are doing validation by Data Annotation? If yes, can your entity with the annotations.
– Randrade
No, I use @Html.Validationmessagefor, this put in Viewmodel.
– jp_almeida
Yes, but you’re decorating your
ViewModel
with some note?[Required]
,[StringLength()]
, etc. Or using EF Fluent API. Validation byjQuery
? What are you using for this?– Randrade
I’m using [Required] myself.
– jp_almeida