简体   繁体   中英

Telerik MVC Controls and JQuery Closure

I have a telerik grid in an asp.net mvc3 (RAZOR) View. While designing I had also bind OnDataBound client event.

@{
    Html.Telerik().Grid() 
        .Name("someGrid")
        .clientEvents(e=>e.OnDataBound("someGrid_onDataBound"))
        .Render();
 }

<script>
function someGrid_onDataBound(e){
  //.. some code which needs to access a function from a JavaScript closure.
}
</script>

In the view I have linked a JavaScript file which contains a Closure for performing different actions. and in the function above I need to call some function from the closure, for this I need to declare this function inside the closure.

Can anybody tell me please how could I make "someGrid_onDataBound" [grid event handler] to access some function from the closure.

As i understand from your question, you wanna put your JS files at the end of the page. And you wanna be able to access them from your Views!.

If so then you should add references to all your JS files and libraries at the end of your _Layout.cshtml right before </body> tag then after these references add new render section @RenderSection("Scripts")

Then put your scripts in suitable section in your Views:

@section Scripts{ 
<script type="text/javascript">
.........
</script>
}

in the closure you have to add the said javascript function to window as follows.

(function($){

// here is your out of closure function

window.someGrid_onDataBound = function(e){

 //.. some code which needs to access a function from a javascript closure.

}

})(jQuery);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM