We can achieve this with the help of @Html.Action()
and @Html.Partial
.
@Html.Action()
requires action method, with the help of action method it rendering the partial page. @Html.Partial()
not required action method, based on the object values it rendering the page. So @Html.Partial()
gives better performance compare to @Html.Action()
.
using Newtonsoft.Json;
@{
string JsonStr = {\"user\":\"me\",\"payment_method\":\"card\",\"items_bought\":[{\"id\":\"001\",\"name\":\"desk\",\"delivered\":\"true\"},{\"id\":\"455\",\"name\":\"chair\","delivered\":\"false\"},{\"id\":\"234\",\"name\":\"mousepad\",\"delivered\":"false\"},{\"id\":\"135\",\"name\":\"cabinet\",\"delivered\":\"false\"}]}
var JsonObject = JsonConvert.DeserializeObject<MyJSON>(JsonStr);
}
<div>
@Html.Partial("_IdentifierPartial", JsonObject)
</div>
The above code will work fine and achieve your requirement. But this approach not advisable, better you can convert the json string to model object in controller side and pass model object to view.
For Ex:
@model ModelClass
<div>
@Html.Partial("_IdentifierPartial",Model.PartialModel)
</div>
Above approach is rendering the page in browser much faster.