Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Why is my partial not updating with new query results?

$
0
0

Hi everyone, I have a partial view with a datapicker on it.  When the user clicks on a link the program calls does a linq query search that looks like this:

 

 

 

 

public ActionResult GetSchedule(string selectedDate)

        {

 

 

          

 

           

            var viewModel = new ScheduleData();

          

        try

        {

            DateTime daySearch = Convert.ToDateTime(selectedDate);

            viewModel.Assignments = from a in db.Assignments where a.teacherId == intTeacherId && a.Date == daySearch select a;

        }

 

        catch {

 

            DateTime theDay = DateTime.Now;

 

            viewModel.Assignments = from a in db.Assignments where a.teacherId == intTeacherId && a.Date == theDay select a;

        }

      

 

 

            return PartialView(viewModel);

       

        }

 

 

 

The program will try to find an item with today’s date initially. If it does it displays this successfully.  Now when I click on the date picker, it calls the ‘GetSchedule’ action again.  This time, however, the partial view does not update with the new query results.  It still displays the initial current day result.

 

The partial view is called like this:

@{

      

    @Ajax.ActionLink("My Schedule", "GetSchedule", "Schedule", new { selectedDate = strToday, initialTeacherId = intTeacherID, instructorname = instructorName, teacherID = intTeacherID }, new AjaxOptions { UpdateTargetId = "diaplayScheduleHere", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" })

 

         }

Then the partial view loads in a div tag with id ‘diaplayScheduleHere’.  

 

Here’s what the partial view looks like:

 

@model SchoolIn.ViewModels.ScheduleData

 

@{Layout = null;}

@{

    ViewBag.Title = "Index";

}

 

 

 

@if (Model.Assignments != null)

{

    

<table>

    <tr>

       <th>

          Assignment  Course

        </th>

      

      

      

        <th>

            Class Day

        </th>

       

      

        <th>

         Class Time

        </th>

       

        <th> You're in assignment on GetSchedule</th>

    </tr>

 

@foreach (var item in Model.Assignments)

{

    <tr>

    <td>

    @{

    int? hh = item.CouresId;

    string coursename = (from x in Model.Courses where x.CourseID == hh select x.Title).Single();

 

 

 

 

    int? tchId = item.teacherId;

    int InstructorId = (from x in Model.Courses where x.CourseID == hh select x.Instructors.FirstOrDefault().InstructorID).Single();

              

       

    string teacherId = tchId.ToString();

 

 <label id="assignmentDataLabel" data-teacher="@teacherId"></label>

     }

   

        @Html.DisplayFor(modelItem => item.Course)

   

    </td>

      

     

        <td>

      

            @item.Date

        </td>

       

      

      

      

    </tr>

}

 

</table>

   

}

 

 

 

  <input type="hidden" autofocus=true/>

 

  <!---div id="partial"-->

 

 <label id = "abc" data-tchId = "9" ></label>

 

    <script type="text/javascript">

 

 

 

 

        $(function () {

 

 

            $(".datepicker").datepicker({ dateFormat: 'mm.dd.yy' });

            $("#dropdownselected1").val($("#categories").val());

 

        });

 

              var teacherData = $("#dataLabel").data("teacher");

        var iDfOfteacher = $("#abc").data("tchId");

 

        var dialogButton;

        $(function () {

 

            $("#datep").datepicker({ showOn: "both", buttonText: "Select Date", changeMonth: true, showButtonBar: true, changeYear: true, yearRange: "-2:+2", showOtherMonths: true, onSelect: function (date, datepickder) {

                var tcherData = { selectedDate: date, teacherID: iDfOfteacher };

 

 

                $.ajax({

                    type: "GET",

                    url: "/Schedule/GetSchedule",

                    data: tcherData,

                    datatype: "html",

                    sucess: function (data) {

 

                    }

                });

 

            }

 

 

 

 

            });

 

 

        });

   

  </script>

 

Tried putting the script at the top of the page, at the bottom of the page, tried refreshing the page with code using “location=location” but the refresh takes the page to an earlier page.

 

My thinking is that it’s an ajax thing.  Something about asynchronous but I don’t know enough to troubleshoot it.  Can someone help me with

Hi everyone, I have a partial view with a datapicker on it.  When the user clicks on a link the program calls does a linq query search that looks like this:

 

 

 

 

public ActionResult GetSchedule(string selectedDate)

        {

 

 

          

 

           

            var viewModel = new ScheduleData();

          

        try

        {

            DateTime daySearch = Convert.ToDateTime(selectedDate);

            viewModel.Assignments = from a in db.Assignments where a.teacherId == intTeacherId && a.Date == daySearch select a;

        }

 

        catch {

 

            DateTime theDay = DateTime.Now;

 

            viewModel.Assignments = from a in db.Assignments where a.teacherId == intTeacherId && a.Date == theDay select a;

        }

      

 

 

            return PartialView(viewModel);

       

        }

 

 

 

The program will try to find an item with today’s date initially. If it does it displays this successfully.  Now when I click on the date picker, it calls the ‘GetSchedule’ action again.  This time, however, the partial view does not update with the new query results.  It still displays the initial current day result.

 

The partial view is called like this:

@{

      

    @Ajax.ActionLink("My Schedule", "GetSchedule", "Schedule", new { selectedDate = strToday, initialTeacherId = intTeacherID, instructorname = instructorName, teacherID = intTeacherID }, new AjaxOptions { UpdateTargetId = "diaplayScheduleHere", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" })

 

         }

Then the partial view loads in a div tag with id ‘diaplayScheduleHere’.  

 

Here’s what the partial view looks like:

 

@model SchoolIn.ViewModels.ScheduleData

 

@{Layout = null;}

@{

    ViewBag.Title = "Index";

}

 

 

 

@if (Model.Assignments != null)

{

    

<table>

    <tr>

       <th>

          Assignment  Course

        </th>

      

      

      

        <th>

            Class Day

        </th>

       

      

        <th>

         Class Time

        </th>

       

        <th> You're in assignment on GetSchedule</th>

    </tr>

 

@foreach (var item in Model.Assignments)

{

    <tr>

    <td>

    @{

    int? hh = item.CouresId;

    string coursename = (from x in Model.Courses where x.CourseID == hh select x.Title).Single();

 

 

 

 

    int? tchId = item.teacherId;

    int InstructorId = (from x in Model.Courses where x.CourseID == hh select x.Instructors.FirstOrDefault().InstructorID).Single();

              

       

    string teacherId = tchId.ToString();

 

 <label id="assignmentDataLabel" data-teacher="@teacherId"></label>

     }

   

        @Html.DisplayFor(modelItem => item.Course)

   

    </td>

      

     

        <td>

      

            @item.Date

        </td>

       

      

      

      

    </tr>

}

 

</table>

   

}

 

 

 

  <input type="hidden" autofocus=true/>

 

  <!---div id="partial"-->

 

 <label id = "abc" data-tchId = "9" ></label>

 

    <script type="text/javascript">

 

 

 

 

        $(function () {

 

 

            $(".datepicker").datepicker({ dateFormat: 'mm.dd.yy' });

            $("#dropdownselected1").val($("#categories").val());

 

        });

 

              var teacherData = $("#dataLabel").data("teacher");

        var iDfOfteacher = $("#abc").data("tchId");

 

        var dialogButton;

        $(function () {

 

            $("#datep").datepicker({ showOn: "both", buttonText: "Select Date", changeMonth: true, showButtonBar: true, changeYear: true, yearRange: "-2:+2", showOtherMonths: true, onSelect: function (date, datepickder) {

                var tcherData = { selectedDate: date, teacherID: iDfOfteacher };

 

 

                $.ajax({

                    type: "GET",

                    url: "/Schedule/GetSchedule",

                    data: tcherData,

                    datatype: "html",

                    sucess: function (data) {

 

                    }

                });

 

            }

 

 

 

 

            });

 

 

        });

   

  </script>

 

Tried putting the script at the top of the page, at the bottom of the page, tried refreshing the page with code using “location=location” but the refresh takes the page to an earlier page.

 

My thinking is that it’s an ajax thing.  Something about asynchronous but I don’t know enough to troubleshoot it.  Can someone help me with why my partial view isn’t updating?

 

Thanks for any help.

 

Thanks for any help.


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>