Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are @Json.Encode or @Json.Decode methods in MVC 6?

What is equivalent of MVC5's @Json.Encode method in MVC6? In MVC5 we can access those methods in views. But I can't find any methods which I can access from MVC 6 views.

I don't want to write a helper method if there is already a built in feature in MVC6.

like image 376
Yves Avatar asked May 18 '15 11:05

Yves


2 Answers

After some search, found it:

@inject IJsonHelper Json;
@Json.Serialize(...)
like image 177
Yves Avatar answered Oct 02 '22 11:10

Yves


I've had success with the following:

@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String)

I'm not sure if Json.Encode has made it in yet because it was a part of System.Web which is gone now.

like image 26
CuddleBunny Avatar answered Oct 02 '22 12:10

CuddleBunny