effkay
effkay

Reputation: 854

ASP .NET MVC; return HTML along with JavaScript

I have a partial view which renders a table.

On page load, I am using JQuery to perform Zebra Stripping on it.

Whenever ajax refreshes the table, DOM elements are updated, but since JQuery code to do the Zebra Stripping is not executed; table looks ugly.

I have tried adding Javascript in my partial view

        if( Request.IsAjaxRequest() )
            return PartialView( "AdministrationGrid", Users );

but javascript is not executed.

I guess the only way to execute the Javascript as reply is to do:

return JavaScript( "alert( '' )" );

Anyone with an idea how can I achieve this?

I thought about JQuery Live, but it is used to bind itself to events.

Upvotes: 0

Views: 1309

Answers (1)

Paddy
Paddy

Reputation: 33867

Surely if you are using AJAX to refresh the table, you have a function that gets called to request your data. If there is an onSuccess function, you could just call the striping in there.

Upvotes: 2

Related Questions