[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

http://forums.asp.net/t/1741372.aspx?pass+model+parameter+to+javascript+function

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
</script>

Hope this can be helpful.

Best Regards,

Eileen

Leave a Reply