CiccioMiami CiccioMiami - 3 months ago 30x
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.



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() {