Sudhir Chavan February 2016

Calling the same Controller with filtered data does not show updated view

I am having a scenario, where my first Index page loads with some detailed data in a row by row fashion. Also I have 3 text boxes RequestID, FromDate and ToDate to filter the data on the page Index view. Once I enter FromDate and ToDate in the respected text boxes and click on a button, through a javascript code I send FromDate and ToDate to the same Index controller to filter the data on the basis of FromDate and ToDate.

The Index controller gets called fine with the parameters FromDate and ToDate, also the data on the basis of FromDate and ToDate gets filtered properly.

But once the filtered data gets send to the Index view to get displayed it doesn't display the filtered data, in spite it shows the existing data.

Please find the below code for your reference.

Below is the Index Controller code.

public ActionResult Index(int? id, DateTime? StartDate, DateTime? EndDate, string status, DateTime? CloseDate)
        {
            IList<ActiveSupportIndexViewModel> activeSupport;

            if(StartDate == null && EndDate == null)
            {
                activeSupport = GetSupportIssueDetails(0, null, null);

            }
            else
            {
                activeSupport = GetSupportIssueDetails(0, StartDate, EndDate);
            }


            return View(activeSupport);
        }

where initially activeSupport = GetSupportIssueDetails(0, null, null) gets called and all data gets displayed.

After entering FromDate and ToDate and by clicking on button activeSupport = GetSupportIssueDetails(0, StartDate, EndDate) gets called and filters the data.

Below is the java script code written.

<script type="text/javascript">
    $(function () {

        $("#Search").click(function () {
            var RID = $('#txtRequestID').val();
            var SDate = $('#txtStartDate').val();
            var EDate = $('#txtE        

Answers


anand February 2016

In the Index page create a partial file with id, in there place the data which show the record.
on ajax success replace the partial file with the ajax data.
Refer this link


Sudhir Chavan February 2016

@Anand

Thanks you for your link. It works fine.

I post the below post of code I change according to your suggestion.

<script type="text/javascript">
    $(function () {

        $("#Search").click(function () {
            var RID = $('#txtRequestID').val();
            var SDate = $('#txtStartDate').val();
            var EDate = $('#txtEndDate').val();
            var stat = $('#selectedRequestID').val();
            var CDate = $('#txtCloseDate').val();

            //alert(stat);

            $.ajax({
                url: 'Home/partialIssueListDetails',
                type: 'GET',
                data: { id: RID, StartDate: SDate, EndDate: EDate, status: stat, CloseDate: CDate },

                success: function (result) {
                    $('#IssueListDetails').html(result);
                },
                error: function () {
                    alert("error");
                }

            });
        });
    });
</script>

Thank you again.

Post Status

Asked in February 2016
Viewed 1,778 times
Voted 13
Answered 2 times

Search




Leave an answer