For accessing Model of View by Javascript I can use
var additional = '@Html.Raw(Json.Encode(Model))';
But how about Model of Partial view from the main view?
The problem I'm facing is I load partial view into a Keno UI window widget via jQuery ajax call, Inside the partial view I have Upload widget and it has some event ( ie: onUpload event ) , if i put the onUpload event inside the partialview, it doesn't recognize it. So I had to put it in Main view.
In that case '@Html.Raw(Json.Encode(Model))' return the Model of Main view and not the partial one.
Any ideas on how to resolve this problem?
This is the way I have access to all of the model:
var model = function () { return @Html.Raw(Json.Encode(Model)) }();
The partial view has a model:
@model SomeModel
<script type="text/javascript">
$(document).ready(function() {
var model = function () { return @Html.Raw(Json.Encode(Model)) }();
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With