Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've just finished coding this for my current work project. I cannot post the code for propitiatory rules. Like your comment above says, there isn't an elegant way. I will describe the steps that we took to display our error messages.</p> <p>First, modify your dynamically generated html so that each has the equivalent code to MVC3 @Html.ValidationFor(...) control. Next each dynamic control needs to have an id field that you can use to locate control to add error message to.</p> <p>Steps I took were, starting after the controller receives the ajax data for validation -</p> <ol> <li><p>Validate the received data model</p></li> <li><p>Create a class to return the results that looks like this</p> <pre><code>Class AjaxResults{ bool success {get; set;); object returnedData {get; set;); } </code></pre></li> <li><p>If model validates, return <code>AjaxResults</code> with <code>success</code> = true and <code>returnedData</code> = "validated data model"</p></li> <li><p>If models does not validate then</p></li> <li>Collect all the errors into a list of pairs. Where key = fieldID and value = "the error message".</li> <li><p>return <code>AjaxResults</code> with <code>success</code> = false and <code>returnedData</code> = "list of errors"</p></li> <li><p>After client receives the <code>AjaxResults</code> object</p></li> <li><p>If <code>success</code> = true, process result normally.</p></li> <li><p>If <code>success</code> = false, iterate through list highlighting the fields with the error and displaying the error message. </p></li> </ol> <p>In the last step, you can use the jquery validation message display the error code. If you want to do this, then in jquery.unobtrusive.valiation.js file</p> <ol> <li>Add code to duplicate the functionality of onError method in the file.</li> <li>Add code to interate through the error list calling your onError method to display the messages. Be careful here in that information is stored in the .data attribute of the Error Message span.</li> <li>You may need to write code to clear all of these errors upon submitting the form.</li> </ol> <p>This is a fairly long procedure. But the code is easily modularized into callable routines. We are currently using this in our production code and in practice, it becomes part of our framework code.</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload