I am new to Asp.net Core MVC. I have a view with validations from which I call a partial view using Jquery and ajax. The partial view displays correctly but the vaidation is not working in the partial view. Its throws up the error 'Uncaught TypeError: Cannot read property 'settings' of undefined at HTMLInputElement.delegate'</div> <div> </div> <div>Posting my code here</div>
@model InventoryModule.Models.Masters.Ledger @{ ViewData["Title"] = "Create"; Layout = "~/Views/Shared/_Layout.cshtml"; }<h2>Create</h2><h4>Ledger</h4><hr /><div class="row"><div class="col-md-4"><form asp-action="Create" asp-antiforgery="true" id="fromLedger"><div asp-validation-summary="ModelOnly" class="text-danger"></div><div class="form-group"><label asp-for="LedgerGroupId" class="control-label"></label><select asp-for="LedgerGroupId" class="form-control" asp-items="ViewBag.LedgerGroupId"><option value="0">--Select Group--</option></select><div class="modal fade" role="dialog" id="ModalCreate"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal">x</button><h4 class="modal-title">Create Product Group</h4></div><div class="modal-body" id="modelPartial"></div></div></div></div><button type="button" class="btn btn-info btn-sm" id="btnModel"> New Group</button></div><div class="form-group"><label asp-for="LedgerName" class="control-label"></label><input asp-for="LedgerName" class="form-control" /><span asp-validation-for="LedgerName" class="text-danger"></span></div><div class="form-group"><label asp-for="Address" class="control-label"></label><input asp-for="Address" class="form-control" /><span asp-validation-for="Address" class="text-danger"></span></div><div class="form-group"><label asp-for="Email" class="control-label"></label><input asp-for="Email" class="form-control" /><span asp-validation-for="Email" class="text-danger"></span></div><div class="form-group"><div class="checkbox"><label><input asp-for="IsActive" /> @Html.DisplayNameFor(model => model.IsActive)</label></div></div><div class="form-group"><input type="submit" value="Create" class="btn btn-default" /></div></form></div></div><div><a asp-action="Index">Back to List</a></div><script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.min.js" asp-fallback-src="~/lib/jquery/dist/jquery.min.js" asp-fallback-test="window.jQuery" crossorigin="anonymous" integrity="sha384-K+ctZQ+LL8q6tP7I94W+qzQsfRV2a+AfHIi9k8z8l9ggpc8X+Ytst4yBo/hH+8Fk"></script><script type="text/javascript">$(document).ready(function () {$("#btnModel").click(function(e) {$.ajax({ type: 'Get', url: '@(Url.Action("ShowPartial","Ledger"))', success: function (respose) {$('#modelPartial').html(respose);$('#ModalCreate').modal('show'); }, cache: false }); }); })</script> @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} }
@model InventoryModule.Models.Masters.LedgerGroup // partial View
@{ string id = ViewData["id"]?.ToString() ?? "0"; }<h4>LedgerGroup</h4><hr /><div class="row"><div class="col-md-4"><form asp-action="Create" id="formLG" asp-antiforgery="true"><div asp-validation-summary="ModelOnly" class="text-danger"></div><div class="form-group"><label asp-for="LedgerGroupName" class="control-label"></label><input asp-for="LedgerGroupName" id="LGName" class="form-control" /><span asp-validation-for="LedgerGroupName" class="text-danger"></span></div><div class="form-group"> @*<input type="submit" asp-route-id=@id value="Create" asp-controller="LedgerGroup" class="btn btn-default" />*@<input type="button" id="submit1" value="Create" class="btn btn-default" /></div></form></div></div><script type="text/javascript">$(document).ready(function () {$("#submit1").click(function(e) { e.preventDefault(); e.enable = false; //debugger; var ledgerGroup = $('#LedgerGroupName').val(); var addAntiForgeryToken = function (data) { data.__RequestVerificationToken = $("[name='__RequestVerificationToken']").val(); return data; }; var data = addAntiForgeryToken({ "LedgergrouId": 0, "LedgerGroupName": ledgerGroup, "id": @id}); //alert(data); // debugger;$.ajax( { type: "POST", url: '@(Url.Action("CreateGroup","LedgerGroup"))', datatype: 'json', data: data, success: function(result) { var groupName = result.ledgerGroupName; var groupId = result.ledgerGroupId;; alert(result); //alert(groupId); $('#LedgerGroupName').val(''); //Add it to the select list in Product Create Ledgergroup Dropdown. $('#LedgerGroupId').append(new Option(groupName, groupId));$('#LedgerGroupId').val(groupId); }, error: function() { alert("Failed"); } }); }); });