I have a class like below:
public class CustomBenefitCommittee
{
public bool? IsChecked { get; set; }
public bool PropertyError { get; set; }
}
And I am using this class as a list type in MVC model like:
@model List<CustomBenefitCommittee>
I want to retrieve data from this model in jQuery. I am trying right now as
@{
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var json = serializer.Serialize(Model);
}
var model = @Html.Raw(json);
if(model != null && @Html.Raw(json) != "undefined")
{
$.each(model, function () {
alert(model.PropertyError );
});
}
This is giving me undefind. Can someone help me out getting the values from this model.
var model = @Html.Raw(Json,Encode(Model)); $.each(model, function(index, item) { alert(item.PropertyError); });var model = @Html.Raw(Json,Encode(Model));This part gives an error of;, Json and Encode.Json.Encode(dot not comma - typo in comment above). And the syntax error for the;can be ignored - its just VS not recognizing perfectly valid code.model.PropertyErrorisundefinedbecausemodelis the collection, not an item in the collection) but you immediately deleted it :) - it was your original answer that was wrong