title: ABP framework - Best way to ValidateModel() and show success message
body: <p><strong>Context</strong>: Web application developed with ASPNet Core over ABP 2.9 framework (Razor pages).</p>
  
  <p>I need to validate a model (it implements <code>Validate(...)</code> from <code>IValidatableObject</code> and calls the application service to perform some validations), then call an application service, and finally show a success message (with the same look &amp; feel as  <code>abp.notify.success(...)</code>).</p>
  
  <p><strong>Purpose</strong> of this post: To validate whether I am following the best practices or doing things in the correct way with ABP framework. If so, there are some suggestions to ABP team.</p>
  
  <p><strong>What I've tried</strong>:</p>
  
  <p>1.- First, I tried submitting the form, but I didn't find an easy way to show the success message (like <code>abp.notify.success</code> ones) from the server method: <code>public virtual async Task&lt;IActionResult&gt; OnPostAsync()</code>.</p>
  
  <p><em>It would be nice to have a simple way to send client messages (like <code>abp.notify.success</code> ones) from server side. Maybe there is a way and I didn't find it.</em> </p>
  
  <p>2.- Second, I tried to cancel form submission and peform validation in client side, call the application service and show the message, also from client side. The issue here is that validations on <code>public IEnumerable&lt;ValidationResult&gt; Validate(ValidationContext validationContext)</code> method were not executed from client side calling <code>form.valid()</code>.</p>
  
  <p><em>Possible improvement to ABP framework would be to enable an easy way to perform same server <code>DataValidation()</code> from client side. Maybe it exists and I didn't find it.</em></p>
  
  <p>3.- Finally, I did the following:</p>
  
  <p>a) Server side: to perform <code>ValidateModel()</code> and call the application service (<a href="https://i.stack.imgur.com/hNThd.png" rel="nofollow noreferrer">see cshtml.cs code</a>). </p>
  
  <p>b) Client Side: avoid form submission and submit it with ajax, and finally show the success message with <code>abp.notify.success(...))</code> (<a href="https://i.stack.imgur.com/6Xw8i.png" rel="nofollow noreferrer">see javascript code</a>).</p>
  
  <hr>
  
  <p>Here are the <strong>questions</strong> related to previous issues. I appreaciate your comments or suggestions:</p>
  
  <p>1.- Is there any better way to perform this scenario using ABP framework utils?</p>
  
  <p>2.- Am I following the best practices? (placing the classes and logic in the correct layers)</p>
  
  <ul>
  <li>DTO with data annotations in Application.Contracts layer.</li>
  <li>DTOValidator class that inherits from DTO and <code>IValidatableObject</code> and implements <code>Validate(...)</code> method in Application.Contracts layer. This is to keep simple DTOs between client and application services.</li>
  <li>Model class that inherits from DTOValidator and is binded to form in .cshtml.cs (Example: <code>public class IndexPolicies : UpdatePolicyDtoValidator {}</code>)</li>
  </ul>