[RESOLVED]How to pass model to javascript function

@Html.EnumDropDownListFor(m => m.VehicleType, new { onchange = string.Format("enablePassengerCount({0})", Model) })

When I try to access the model in javascript it is always null. What is the correct way of passing a model to a javascript function?

Check this


Hi preetahb,

Thanks for your post.

I think you can convert your model to json object,like this:

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

Hope this can be helpful.

Best Regards,


Leave a Reply