1

How do I convert a Model to a JSON object in ASP.NET Core MVC?

I used to use the Json.Encode() method in MVC 5, but I cannot get this to compile in ASP.NET Core MVC. What is the replacement?

1 Answer 1

1

Upto MVC 5, Json.Encode() works. But in MVC Core, we don't have Encode() method. Instead of it, we have Serialize() method. You can convert Model/ViewBag to json object as follows,

var x = @Html.Raw(Json.Serialize(Model));
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.