This article shows how to use a JSON result in a controller in MVC.
IntroductionThis article shows how to use a JSON result in a controller in MVC.Step 1Create a MVC project from the "Empty" template.Right-click on "Controllers" and select "Add" >> "Controller...".Step 2Select "MVC 5 Controller - Empty" to add an empty controller.Click on the "Add" button.Step 3Name the controller as in the following:And it will add an action result method to the controller.Step 4Now we need to create a view.Right-click on "Index" and select "Add View...".Step 5Name the view and select "Empty (without model)" as the template.Click on the "Add" button.Step 6Add a title in the index page.Step 7JsonResult is used to send JSON formatted content to the response. Create an object of employee inside the jsonresult method and return a jsonresult object. Commented code represents another way to create a jsonresult object. Step 8Create a link to call the "jsonResult" method in index.cshtml.Step 9Run the project, click on the "JsonResult" link and you can see the JSON data rendered on the browser.
Hands on ASP.NET GridView