Click here to Skip to main content
15,905,590 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am facing a strange issue in webgrid sorting url.

On first load it renders with url of ActionName. Say if url is //hostname/mysite/GetAction then webgrid renders the sorting url as //hostname/mysite/GetAction?sort=col1&sortdir=ASC

So far so good.

But problem arises when i click to sort one of the column on webgrid it changes to different url. It renders with action url of the Form under which it is placed in HTML.

Or i executed different Action then href for all anchor like paging and sorting is changed.
Posted
Updated 9-Dec-15 8:44am
v2

1 solution

C#
I was also facing the same issue like lost of original URL for Sorting and paging for WebGrid Control in MVC.I did some custom solution.

Please find it here .This is in JQuery.Please let me know for any query.

For first time on page load i am Storing Original URL in Hidden.


function SetHref()
{
    $('#checkableGrid').find('a').each(function () {
        var URL = this.href.split('?')[0]        
        var hiddenhrefval = $("#hiddenhref").val();
        if(URL != "" && URL != undefined)
        {
            if (hiddenhrefval == "") {
                $("#hiddenhref").val(URL);
            }
        }               
    });    
    }

This is Calling on Document.ready

Now On every change of Action or calling some different method i am getting Original URL from Hidden and setting it back to original URL.


    function GetHref()
    {
        $('#checkableGrid').find('a').each(function () {        
            var URLArray = this.href.split('?')        
            var URLWithoutQryString = URLArray[0];        
            var URLQryString= URLArray[1];            

            var hiddenhrefval = $("#hiddenhref").val();       
            if (URLWithoutQryString != hiddenhrefval)
            {
                var CompleteURL = hiddenhrefval + "?" + URLQryString;
                $(this).attr("href", CompleteURL);                
            }
        });
    }






//While changing status in drop Down filtering
function ChangeStatus() {
    $("#CRFStatus").on("change", function () {
        var CRFStatusID = $("#CRFStatus").val();               
        if (CRFStatusID != "") {

            RenderCRFQueueItemsList(CRFStatusID);

            
            GetHref();
        }
        else
        {
            $('#CRFStatus option:contains("--Select Status--")').prop('selected', true);
        }   
    });   
}

This would set all anchor href to original.
 
Share this answer
 
Comments
Suvendu Shekhar Giri 9-Dec-15 14:53pm    
Posting an answer yourself, after 2 minutes of posting the question?
raj kumarpandey 9-Dec-15 14:59pm    
i had struggled a lot so didn't want others to suffer so posted question and answer both so that it can help others as i didn't find readymade answer for this issue so did custom solution. If any one has better solution please post here i would like to changes my solution as i was running out of time and struggled .Please any one has better solution please port it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900