How to use more than 1 'div Asp-validation-Summary' in the same Razor view?

Asked

Viewed 112 times

1

I have a Razor view that has two different forms, one of Login and the other of User Registration, I built both forms and I inserted as usual the tag with asp-validation-summary

<div asp-validation-summary="All" class="text-danger"></div>

in both forms, however when testing I identified that when an inconsistency of the validation of the Login or Cadastro both

<div asp-validation-summary="All" class="text-danger"></div>

remain with the inconsistency. I searched in the documentation something that avoids this problem, but there is nothing, there is some solution Bailiff or some Workaround?

In addition to inserting both forms into the same view, I also tested by inserting each form into a separate but unsuccessful partial view.

Technologies involved: Asp.Net Core 2.0 and Razor (View)

Simple code for playback:

<form asp-controller="Conta" asp-action="Login" autocomplete="off">
    <div asp-validation-summary="All" class="text-danger"></div>

    <input asp-for="Email" placeholder="@Html.DisplayNameFor(x => x.Email)" />
    <span asp-validation-for="Email" class="text-danger"></span>

    <input asp-for="Senha" placeholder="@Html.DisplayNameFor(x => x.Senha)" />
    <span asp-validation-for="Senha" class="text-danger"></span>

    <button type="submit" class="btn btn-default">Enviar</button>
</form>

<form asp-controller="Conta" asp-action="CadastroCliente" autocomplete="off">
        <div asp-validation-summary="All" class="text-danger"></div>

        <input asp-for="NomeCliente" placeholder="@Html.DisplayNameFor(x => x.NomeCliente)" />
        <span asp-validation-for="NomeCliente" class="text-danger"></span>

        <input asp-for="CPF" placeholder="@Html.DisplayNameFor(x => x.CPF)" />
        <span asp-validation-for="CPF" class="text-danger"></span>

        <input asp-for="EmailCliente" placeholder="@Html.DisplayNameFor(x => x.EmailCliente)" />
        <span asp-validation-for="EmailCliente" class="text-danger"></span>

        <input asp-for="SenhaCliente" placeholder="@Html.DisplayNameFor(x => x.SenhaCliente)" />
        <span asp-validation-for="SenhaCliente" class="text-danger"></span>

        <button type="submit" class="btn btn-default">Cadastrar</button>
    </form>
  • Have you tested in partialview but with different models? (One for each) and in the Asp-validation-Summary configuration you tried this:<div Asp-validation-Summary="Modelonly" class="text-Danger"></div>

  • @Rafael yes as different models

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.