-2

I am using MVC webgrid and an artifact of navigating the page is I have lots of urls that look like like:

<a href="/SyntheticData/MasterDetail?modelIn=Exact.Web.ViewModel.MasterDetailViewModel&amp;entrystate=Templates&amp;selectedrow=5">►</a>

I need to change entrystate=Templates to entrystate=Paging.

Is there a jscript way to make this change for all the links in a simple script ?

The links are being generated by the webgrid component and I have no access to it. They seem to be formed because the grid takes the url that invokes the action and uses it as a base url (entrystate and modelIn are routevalues invoking the action). I have no control over this. My only option seems to be fixing the html after it is created. I am stuck with this lame grid.

jlo-gmail
  • 4,453
  • 3
  • 37
  • 64

2 Answers2

2

Try this:

$('a[href~="/SyntheticData/MasterDetail?"]').each(function() {
  $(this).attr('href', $(this).attr('href').replace('entrystate=Templates', 'entrystate=Paging'));
});

I used a wildcard selector to partially match the href so it doesn't loop through links that are unrelated. You may need to adjust it.

oops, you aint using jquery perhaps?

suncat100
  • 2,118
  • 1
  • 17
  • 22
0

I was hoping for something simplter but this looks like it will work:

var links = $("a[href]");
for (var i = 0; i < links.length; i++) {
    var link = links[i];
    var urlin = link.attributes.getNamedItem("href");
    var urlout = urlin.value.replace("entrystate=Templates", "entrystate=Paging");
    var urlout2 = urlout.replace("entrystate=Designer", "entrystate=Paging");
    link.setAttribute("href", urlout2);
}

I ended up using (thx suncat100):

    $('a[href*="entrystate="]').each(function () {
        var url = $(this)[0].attributes.getNamedItem("href").value;
        url = url.replace("entrystate=Templates", "entrystate=Paging");
        url = url.replace("entrystate=Designer", "entrystate=Paging");
        $(this)[0].setAttribute("href", url);
    });
});
jlo-gmail
  • 4,453
  • 3
  • 37
  • 64