I read this and tried to implement the ViewDataDictionary
in my app but did not work.
In my view, I've the below code:
@{
var myTest = new
{
UserId = "cdb86aea-e3d6-4fdd-9b7f-55e12b710f78",
UserName = "iggy",
};
}
@Html.Partial("~/Partials/test.cshtml", myTest)
and the test.cshtml
is very simple, when I write @Model
, I get { UserId = cdb86aea-e3d6-4fdd-9b7f-55e12b710f78, UserName = iggy }
How can I extract this as JSON, so I can read @Model.UserName
I tried using:
<script type="text/javascript">
@
{
<text>
var obj = JSON.parse(@Model);
</text>
}
</script>
and tried:
<script type="text/javascript">
@:var obj = JSON.parse(@Model);
</script>
and tried:
@Html.Raw(Json.Encode(object))
but nothing worked, any help!!