Reputation: 2092
In my html, I use Model.Subcontract.company
How can I reference that data in my jQuery?
Upvotes: 1
Views: 15233
Reputation: 4021
This is an effective way to reference the model as an object in jQuery:
var model = @Html.Raw(Json.Encode(Model))
If you want to avoid the harmless, intellisense error:
var model = [@Html.Raw(Json.Encode(Model))][0];
Upvotes: 1
Reputation: 2092
I was able to do it like this:
"<%= Model.Subcontract.company %>"
It's always easier to figure it out after you've given up and asked the question!
Upvotes: 0
Reputation: 38503
Set the value to an html element and then access it via jquery.
<input type="hidden" value="<%= Model.Subcontract.Company %>" id="hidData" name="hidData" />
$("#hidData").val();
Upvotes: 1