In my model I have one int object and a boolean array:
public class mymodel
{
public int Round { get; set; }
public Boolean[] lstLabs { get; set; }
}
In my view I write this :
<script type="text/javascript">
var objModel = {
Round:"@Model.Round",
lstLabs: "@Model.lstLabs"
};
</script>
I get only the value of Round (the int object) , but I can't get the array , I just get this : lstLabs : System.Boolean[] , I tried : lstLabs: @Model.lstLabs.slice()
but it didn't work , I got the same thing...
Can anyone help me ?
Thanks in advance.
If you want all properties of the view model:
<script type="text/javascript">
var objModel = @Html.Raw(Json.Encode(Model));
alert(objModel.Round + ' ' + objModel.lstLabs.length);
</script>
or if you want only a subset:
<script type="text/javascript">
var objModel = @Html.Raw(Json.Encode(new {
Labs = Model.lstLabs
}));
alert(objModel.Labs.length);
</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