Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding Client-Side Validation to Partial View with AjaxOptions.OnSuccess
    primarykey
    data
    text
    <p>I've been trying to enable client-side validation for a partial view and I've found myself stuck. I've added the code to the AjaxOptions OnSuccess property, but nothing happens. I should point out that I'm relatively new to jQuery and, to be honest, I'm trying to work my way through my first MVC application by learning as I go. If anyone has a better way of doing this,please let me know.</p> <p>Any help would be greatly appreciated.</p> <p>The code for my view is as follows:</p> <pre><code>@model NorthwindLight.Models.Order @using NorthwindLight.HtmlHelpers @using NorthwindLight.Models @{ ViewBag.Title ="Create"; AjaxOptions newOpts = new AjaxOptions(); newOpts.UpdateTargetId ="tabledata"; newOpts.InsertionMode =InsertionMode.InsertAfter; newOpts.OnSuccess ="function (tabledata) {$.validator.unobtrusive.parse($(tabledata));};"; } &lt;h2&gt;Create&lt;/h2&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt; @using (Html.BeginForm("Create", "Order", FormMethod.Post, new { name = "mainform", id = "mainform" })) { @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend&gt;Order&lt;/legend&gt; ... Code for entering Order ommitted for brevity &lt;legend&gt;Order Details&lt;/legend&gt; &lt;br /&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Product&lt;/th&gt; &lt;th&gt;Unit Price&lt;/th&gt; &lt;th&gt;Quantity&lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody id="tabledata"&gt; @if (Model.OrderDetails == null) { @Html.Partial("OrderDetailPartial", new OrderDetail()) } else { foreach (var orderDetail in Model.OrderDetails) { @Html.Partial("OrderDetailPartial", orderDetail) } } &lt;/tbody&gt; &lt;/table&gt; @Ajax.ActionLink("New Record", "OrderDetailPartial", newOpts) &lt;/fieldset&gt; } &lt;div&gt; &lt;a href="javascript:document.mainform.submit();"&gt;Create&lt;/a&gt; | @Html.ActionLink("Cancel", "Index") &lt;/div&gt; </code></pre> <p>Here are the script tags that are included in _Layout.cshtml</p> <pre><code>&lt;script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/DeleteRow.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/ui.core.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/ui.datepicker.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>I've seen lots of examples on the net that seem similar to this, but I've not been able to get any of them to work.</p>
    singulars
    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. 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