CiccioMiami CiccioMiami - 1 year ago 310
Javascript Question

How to pass parameters to jQuery document.ready() function (ASP.NET MVC, C#)

I would like to pass a parameter to the jQuery document.ready() function from my View:

$(document).ready(function (parameter){

How can I fire the event from my View and pass the parameter? I use Razor as View engine.


Answer Source

You can't. The document.ready function doesn't take parameters. You could for example define this parameter as a global variable in your view:

<script type="text/javascript">
    var model = @Html.Raw(Json.Encode(Model));

and then in your separate javascript file use this global variable:

$(function() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download