How to return the JSON from action method in ASP.Net MVC?



How to return the JSON from action method in ASP.Net MVC?..

Answer / Shamim Ahmad

To return JSON from an action method in ASP.NET MVC, you can use the `JsonResult` class. Here's a simple example:
```
public ActionResult GetData()
{
var data = new { Key1 = "Value1", Key2 = "Value2" };
return Json(data);
}
```
In this example, the method returns a JSON object containing 'Key1' and 'Key2' properties.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Dot Net Framework Interview Questions

Is dapper faster than entity framework?

1 Answers  


what is ssdl?

1 Answers   Microsoft,


What is MVVM design pattern?

1 Answers  


When using razor views, do you have to take any special steps to protect your asp.net mvc application from cross site scripting (xss) attacks?

1 Answers  


How we can invoke child actions in ASP.Net MVC?

1 Answers  


Possible ways to prevent xss attacks on mvc application?

0 Answers  


What is meant by bootstrap in mvc5?

1 Answers  


how do you mark a property as required? For example, for a project, the name is a required field.

1 Answers   Microsoft,


Can I add asp.net mvc testcases in visual studio express?

1 Answers  


What are the new features 3.5 framework against with the tool?

1 Answers  


What are the ways to deploy an assembly?

3 Answers  


WHICH IS MORE SECURED AMONG JAVA AND .NET?

7 Answers  


Categories