Note that there are some explanatory texts on larger screens.

plurals
  1. POserver side validation in jquery dialog
    primarykey
    data
    text
    <p>sorry for my language - in English i can only read :)<br/><br/> i want to do in asp.net mvc something like this:<br/> 1. show user a page<br/> 2. open modal dialog (jquery-ui) and show partial view<br/> 3. validate user input data on client side<br/> 4. if it's OK then validate input data on server<br/> 5a. if it's OK then i want reload page<br/> 5b. if there is a errors i want show its to user<br/> 6. user can close dialog at any time with button on it.<br/> <br/> i have problem width 5a and 6.<br/> <br/> in Firefox when i do server validate and click close button (dialog('close')) when i get redirect to page that was call to validate data. if i click 'x' in header of dialog box it's close OK. In opera it's the same situation.<br/> <br/> additional in Firefox when i insert a good data and validation on server pass dialog box don't close (it's work in opera).<br/> i don't have big experience in mvc and don't know if i do it right. please look at my code and tell me if it's wrong and i shouldn't do it that way.</p> <p>controler code:<br/></p> <pre><code>public ActionResult Create()&lt;br/&gt; { return PartialView(new UserDTO()); } [HttpPost] public ActionResult Create(UserDTO model) { if(model.Email != "fromasz@gmail.com") { ModelState.AddModelError("Email", "wrong email"); return PartialView(model); } return new EmptyResult(); } </code></pre> <p>// javascript on index page</p> <pre><code>&lt;script type="text/javascript"&gt; var dialog; $(document).ready(function () { dialog = $("#divInsert").dialog({ title: "Insert", resizable: false, modal: true, autoOpen: false }); $("#aShowInsert").click(function () { $("#divInsert").empty(); $("#divInsert").load("Home/Create", function () { $("#inputCloseModal").click(function () { dialog.dialog('close'); return false; }); }); dialog.dialog("open"); return false; }); }); &lt;/script&gt; </code></pre> <p><br/></p> <pre><code>&lt;div id="divInsert" /&gt; - its a dive where i loads form. &lt;a id="aShowInsert"&gt;add element&lt;/a&gt; - link thats open dialog. </code></pre> <p>I import js files in order: jquery-1.6.1.js, jquery-ui-1.8.13.js, jquery.validate.js, jquery.validate.unobtrusive.js<br/><br/> the form view looks like that:</p> <pre><code>// import js.. @using (Html.BeginForm()) { @Html.ValidationSummary(true) &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Name) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Name) @Html.ValidationMessageFor(model =&gt; model.Name) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Surname) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Surname) @Html.ValidationMessageFor(model =&gt; model.Surname) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Email) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Email) @Html.ValidationMessageFor(model =&gt; model.Email) &lt;/div&gt; &lt;p&gt; &lt;input type="submit" value="Create" id="inputSubmit" /&gt; &lt;input type="submit" value="Close" id="inputCloseModal" /&gt; &lt;/p&gt; } &lt;script type="text/javascript"&gt; $("#inputSubmit").click(function (e) { e.preventDefault(); var form = $("#divInsert form"); form.validate(); if (form.valid()) { $.ajax({ url: "/Home/Create", data: form.serialize(), type: "POST", success: function (data) { if (data === "") { location.reload(); } else { $("#divInsert").html(data); $.validator.unobtrusive.parse($("#divInsert")); } } }); } return false; }); </code></pre> <p></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.
 

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