SubSummerRepairListCollection

SubSummerRepairListCollection

本文介绍了jquery datepicker在MVC中部分回发后没有识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个空表,有五行空行,我有一个Datepicker字段。当我点击Add按钮时,我有一个添加按钮,一个空行将附加到表格中。 Datepicker字段在单击Add按钮之前工作正常,但是当我点击添加按钮时,Datepicker无法通过以下代码识别。 < div class =panel-body> < div class =row> < div class =col-sm-12> @for(int i = 0; i< SubSummerRepairListCollection.Count; i ++) { var StyleShow =display:+(SubSummerRepairListCollection [i] .SummerRepairID = = null?block:none); var StyleNone =display:+(SubSummerRepairListCollection [i] .SummerRepairID == null?none:block); if(i == 0) { btnAddNewShow = SubSummerRepairListCollection [i] .SummerRepairID == null?真假; } < div class =SubSummer> < div class =col-sm-4 text-center> @ Html.HiddenFor(m => SubSummerRepairListCollection [i] .SummerRepairID,new {@id =hidSummerRepairID}) @ Html.TextBoxFor(m => SubSummerRepairListCollection [i] .LocationOfRepairs, htmlAttributes:new {@class =form-control m-bot15,@ style = StyleShow}) @ Html.Label(,(SubSummerRepairListCollection [i]!= null?(SubSummerRepairListCollection [i] .LocationOfRepairs != null?SubSummerRepairListCollection [i] .LocationOfRepairs.ToString():):),new {@style = StyleNone,@ class =lblForms})< / div> < div class =col-sm-4 text-center> @ Html.TextBoxFor(m => SubSummerRepairListCollection [i] .DescribeWorkRepairNeeded,htmlAttributes:new {@class =form-control m-bot15,@ style = StyleShow}) @ Html.Label (,(SubSummerRepairListCollection [i]!= null?(SubSummerRepairListCollection [i] .DescribeWorkRepairNeeded!= null?SubSummerRepairListCollection [i] .DescribeWorkRepairNeeded.ToString():):),new {@style = StyleNone, @class =lblForms}) < / div> < div class =col-sm-4 text-center> @ Html.TextBoxFor(m => SubSummerRepairListCollection [i] .DesireCompletionDate,htmlAttributes:new {@class =form-control m-bot15,@ style = StyleShow,@ id =txtDesireCompletionDate,@ onkeypress =return isDateKey(event)}) @ Html.Label(,(SubSummerRepairListCollection [i]!= null?(SubSummerRepairListCollection [i] .DesireCompletionDate!= null?Convert.ToDateTime(SubSummerRepairListCollection [i] .DesireCompletionDate.ToString())。ToString(MM / dd / yyyy):):),new {@style = StyleNone,@ class =lblForms})< / div> ; < / div> } < / div> < / div> < / div> 脚本代码 $( function (){ $(' .SubSummer')。find(' #txtDesireCompletionDate')。datepicker({格式:' mm / dd / yyyy',startDate : new 日期(),autoclose: true }); $(' #btnAddNew')。点击( function (e){ e.preventDefault(); var ArraySubSummer = 数组(); $(' .SubSummer')。each( function (index,item){ var obj = new Object(); obj.SummerRepairID = $( this )。find(' #hidSummerRepairID')VAL(); obj.LocationOfRepairs = $( this )。find(' :text')[ 0 ]。value; obj.DescribeWorkRepairNeeded = $( this )。find(' :text')[ 1 ]。value; obj.DesireCompletionDate = $( this )。find(' :text')[ 2 ]。value; ArraySubSummer.push(obj); }); $ .ajax({ url: @(Url.Action( AddNewSubSummerRepairWorkOrder , Forms )),类型:' POST' , contentType:' application / json; charset = utf-8' ,数据:' {lstSubSummerRepair:' + JSON .stringify(ArraySubSummer)+ ' }',成功: function (结果){ $( #SubSummerRepairCont 。ENT)HTML(结果); } }); return false ; }); }); 解决方案 ( function (){ (' .SubSummer')。find(' #txtDesireCompletionDate')。datepicker({ format:' mm / dd / yyyy',startDate: new 日期(),autoclose: true }); (' #btnAddNew')。click( function ( e){ e.preventDefault(); var ArraySubSummer = 数组( ); I have an empty table with five empty rows under which I had a Datepicker field. I had an add button when I click on Add button one empty row will append to the table. Datepicker field is working fine before clicking on Add button but when I click on add button Datepicker is not identifying by the following code. <div class="panel-body"> <div class="row"> <div class="col-sm-12"> @for (int i = 0; i < SubSummerRepairListCollection.Count; i++) { var StyleShow = "display:" + (SubSummerRepairListCollection[i].SummerRepairID == null ? "block" : "none"); var StyleNone = "display:" + (SubSummerRepairListCollection[i].SummerRepairID == null ? "none" : "block"); if (i == 0) { btnAddNewShow = SubSummerRepairListCollection[i].SummerRepairID == null ? true : false; } <div class="SubSummer"> <div class="col-sm-4 text-center"> @Html.HiddenFor(m => SubSummerRepairListCollection[i].SummerRepairID, new { @id = "hidSummerRepairID" }) @Html.TextBoxFor(m => SubSummerRepairListCollection[i].LocationOfRepairs, htmlAttributes: new { @class = "form-control m-bot15", @style = StyleShow }) @Html.Label("", (SubSummerRepairListCollection[i] != null ? (SubSummerRepairListCollection[i].LocationOfRepairs != null ? SubSummerRepairListCollection[i].LocationOfRepairs.ToString() : "") : ""), new { @style = StyleNone, @class = "lblForms" }) </div> <div class="col-sm-4 text-center"> @Html.TextBoxFor(m => SubSummerRepairListCollection[i].DescribeWorkRepairNeeded, htmlAttributes: new { @class = "form-control m-bot15", @style = StyleShow }) @Html.Label("", (SubSummerRepairListCollection[i] != null ? (SubSummerRepairListCollection[i].DescribeWorkRepairNeeded != null ? SubSummerRepairListCollection[i].DescribeWorkRepairNeeded.ToString() : "") : ""), new { @style = StyleNone, @class = "lblForms" }) </div> <div class="col-sm-4 text-center"> @Html.TextBoxFor(m => SubSummerRepairListCollection[i].DesireCompletionDate, htmlAttributes: new { @class = "form-control m-bot15", @style = StyleShow, @id = "txtDesireCompletionDate", @onkeypress = "return isDateKey(event)" }) @Html.Label("", (SubSummerRepairListCollection[i] != null ? (SubSummerRepairListCollection[i].DesireCompletionDate != null ? Convert.ToDateTime(SubSummerRepairListCollection[i].DesireCompletionDate.ToString()).ToString("MM/dd/yyyy") : "") : ""), new { @style = StyleNone, @class = "lblForms" }) </div> </div> } </div> </div> </div>Script Code $(function () { $('.SubSummer').find('#txtDesireCompletionDate').datepicker({ format: 'mm/dd/yyyy', startDate: new Date(), autoclose: true }); $('#btnAddNew').click(function (e) { e.preventDefault(); var ArraySubSummer = Array(); $('.SubSummer').each(function (index, item) { var obj = new Object(); obj.SummerRepairID = $(this).find('#hidSummerRepairID').val(); obj.LocationOfRepairs = $(this).find(':text')[0].value; obj.DescribeWorkRepairNeeded = $(this).find(':text')[1].value; obj.DesireCompletionDate = $(this).find(':text')[2].value; ArraySubSummer.push(obj); }); $.ajax({ url: "@(Url.Action("AddNewSubSummerRepairWorkOrder", "Forms"))", type: 'POST', contentType: 'application/json; charset=utf-8', data: '{ "lstSubSummerRepair":' + JSON.stringify(ArraySubSummer) + '}', success: function (result) { $("#SubSummerRepairContent").html(result); } }); return false; }); }); 解决方案 (function () {('.SubSummer').find('#txtDesireCompletionDate').datepicker({ format: 'mm/dd/yyyy', startDate: new Date(), autoclose: true });('#btnAddNew').click(function (e) { e.preventDefault(); var ArraySubSummer = Array(); 这篇关于jquery datepicker在MVC中部分回发后没有识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 20:47