如何将主视图值提供给局部视图甚至继续更改?

时间:2016-04-07 11:10:23

标签: c# jquery asp.net-mvc

在下图中:上面部分是我的创建视图,下面部分是局部视图。 所以,当我点击“搜索”时创建视图的按钮然后可以通过jquery load方法将所有值发送到局部视图。

但是在输入部分视图的所有条目后,最终用户更改创建视图的任何值,然后单击“提交”#39;按钮局部视图然后获取旧值不会得到更改的值..

那么如何获得改变的价值呢?

从这里开始我传递创建视图值。

$("#Search").live("click", function () {
            if ($("#formID").validationEngine('validate')) {
                Loader.Show();                
                $(".validation-summary-errors").empty();
                $("#StudentList").empty();
                $("#StudentList").html("");  
          $("#StudentList").load("/../Student_Exam_Allocation/ExamAlocation_To_Class?CompanyId=" + $("#Company_Id").val() + "&CompanyLocationId=" + $("#Company_location_Id").val() + "&AcademicId=" + $("#Academic_Year_Id").val() + "&ClassID=" + $("#Class_Id").val() + "&ExamId=" + $("#Exam_Id").val(), function () {
                    Loader.Hide();
                });
            }
        });

从这里我将值传递给部分视图,其中包含来自数据库的额外数据

public PartialViewResult ExamAlocation_To_Class(long? CompanyId, long? CompanyLocationId, long AcademicId, long? ClassID, long? ExamId)
        {           
            List<CUSTOM_EXAM_DETAIL> SubjectList = new List<CUSTOM_EXAM_DETAIL>();
            if (CompanyId != null && CompanyId != 0 && CompanyLocationId != null && CompanyLocationId != 0)// && AcademicId != null && AcademicId != 0 && ClassID != null && ClassID != 0)
            {
                SubjectList = (from a in db.Student_Subject_Master
                                where a.Delete_Flag==false                            
                               select new CUSTOM_EXAM_DETAIL
                           {                               
                               Subject_Id = a.Subject_Id,
                               Class_Id = ClassID,
                               Academic_Year_Id = AcademicId,
                               Exam_Id= ExamId,
                               Subject_Name= a.Subject_Name,
                               Subject_Code=a.Subject_Code,
                               Subject_Type=a.Subject_Type,
                           }).OrderBy(a => a.Subject_Id).ToList();
            }

            ViewBag.SubjectList_List = SubjectList.ToList();
=> a.Delete_Flag == false && a.Company_ID == CompanyId && a.COMPANY_LOCATION_ID == CompanyLocationId), "Subject_Id", "Subject_Name");
            return PartialView();
        }
下面的

是带有绑定控件的部分值。

<tbody class="TableData">
                @{
                    var count=0;
                    string Transferprefix = "CUSTOM_Exam_M_DETAIL[{0}].";                    
                    string strTransferprefix = "";
                    foreach (var subject in ViewBag.SubjectList_List)
                   {
                       strTransferprefix = String.Format(Transferprefix, count);
                        <tr rownumber="@count">
                         <td align="center" width="2%">
                        <input type="checkbox" name="@(strTransferprefix + "Selected_Subject")" id="@("Selected_Subject-" + count)" class="SelectSubject" value="True" checked="checked" />  
                        <input type="hidden" name="@(strTransferprefix + "Subject_Id")" id="@("Subject_Id-" + count)" class="reg" value="@subject.Subject_Id" />
                        <input type="hidden" name="@(strTransferprefix + "Class_Id")" id="@("Class_Ids-" + count)" value="@subject.Class_Id" /> 
                        <input type="hidden" name="@(strTransferprefix + "Academic_Year_Id")" id="@("Academic_Year_Ids-" + count)" value="@subject.Academic_Year_Id" /> 
                        <input type="hidden" name="@(strTransferprefix + "Exam_Id")" id="@("Exam_Ids-" + count)" value="@subject.Exam_Id" />                            
                         </td>
                         <td align="center" width="5%">
                            @subject.Subject_Name (@subject.Subject_Code)

                            </td>   
                            <td align="center" width="10%">
                                <input type="text" name="@(strTransferprefix + "Exam_Date")" id="@("Exam_Date-" + count)" class="cssdateclass" />

                                <span id="@("SapnExam_Date-" + count)" style="color:Red;"></span>

                                <script type='text/javascript'>
                                $(function () {
                                $("#@("Exam_Date-" + count)").datepicker({changeMonth: true, changeYear: true});
                                });
                                </script>

                            </td>
                            <td align="center" width="8%">
                              <input  type="text" name="@(strTransferprefix + "Start_Time")" id="@("IN_TIME-" + count)" class="intime timepicker validate[required]" size="8%" rownumber="@count" />

                               <span id="@("SapnStart_Time-" + count)" style="color:Red;"></span>
                            </td>
                            <td align="center" width="8%">
                              <input  type="text" name="@(strTransferprefix + "End_Time")" id="@("OUT_TIME-" + count)" class="outtime timepicker validate[required]" size="8%" rownumber="@count"/>

                               <span id="@("SapnEnd_Time-" + count)" style="color:Red;"></span>
                            </td>
                            <td width="8%" align="left">

                                <input type="text" name="@(strTransferprefix + "Duration")" id="@("Duration-" + count)" class="cssclass" readonly="readonly" style="background-color:#E0E0E0"/>
                            </td>
                            <td align="center" width="10%">
                                <input type="text" name="@(strTransferprefix+"Pass_Marks")" id="@("Pass_Marks-" + count)" class="cssclass validate[required]"/>

                                <span id="@("SapnPass_Marks-" + count)" style="color:Red;"></span>
                            </td>
                            <td align="center" width="10%">
                                <input type="text" name="@(strTransferprefix+"Max_Marks")" id="@("Max_Marks-" + count)" class="cssclass validate[required]"/>
                                <span id="@("SapnMax_Marks-" + count)" style="color:Red;"></span>
                            </td>

                    </tr>
                       count++;
                   }
                }
                </tbody>

我尝试过如下但没有得到价值。

$( "#Company_Id" ).change(function() {
            $("#Company_Ids").val($(this).val());
        });
        $( "#Company_location_Id" ).change(function() {
            $("#Company_location_Ids").val($(this).val());
        });
        $( "#Academic_Year_Id" ).change(function() {
            $("#Academic_Year_Ids").val($(this).val());
        });
        $( "#Class_Id" ).change(function() {
            $("#Class_Ids").val($(this).val());
        });

其中Company_Id,Company_location_Id,Academic_Year_Id和Class_Id是创建视图的隐藏控件。 而Company_Ids,Company_location_Ids,Academic_Year_Ids和Class_Ids是部分视图的隐藏控件。

0 个答案:

没有答案