5

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.

0

1 Answer 1

7

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.