Await html renderpartialasync validationscriptspartial

For data validation, where to add Html.RenderPartialAsync(«_ValidationScriptsPartial»)?

In my ASP.NET Core 1.1.1 app the model validation is not working. I’ve noticed that some of the default views (such as login.cshtml , Register.cshtml that were created by VS2017 when the app was created) have the following code at the end. But these default views are in fact partial views. My Views are not partial views, should the following be added to end of my views as well? Or what should I be adding to the end of my views that are not partial views:

When you say that «is not working» what do you mean? It can be «not working» on client (javascript), «not working» on server (can be many things). What exactly is happening (define «not working»)?

1 Answer 1

is used for «client side validation» (javascript). It does not let the user send the form if it is not valid (according to Model Validation).

If you open your /Views/Shared/_Layout.cshtml you´ll see at the bottom of it the following code:

@RenderSection("Scripts", required: false) 

This code block is where the content from @section Scripts will be injected, in these case, the content of the Partial View _ValidationScriptsPartial .

As required: false , if your view does not need client validation you does not need to add the @section Scripts code.

Regarding the Partial in _ValidationScriptsPartial view name it means that the view itself is partial, it is not intended to be served directly. It must not be confused with «it should be used in partial views».

Источник

Читайте также:  Reversing arraylist in java
Оцените статью