Formatting JSON in ASP.NET MVC -
I want to return a JSON with ASP.NET MVC action, the result type method that looks like this: How do I format it? Right now I have something like this EDIT: I am using VB.NET but the answer in C # is also fine. I prefer manually using ViewModels instead of creating complex JSON responses Ensures that the data come back, and the strongly typed properties are easy to work with IMHO. and then just: Additionally, you use a base class for each response The advantage of doing is, if there are general data like success status, or error message. }); or if it succeeds
returns Jason (new {with key. Success = "true", key.username = responseJsonString}, JsonRequestBehavior.AllowGet)
Response Response = New Response (); Response. Returns to Success = True; // Jason (Response) to the rest of the data;
Public Class Response {Public Child Success {Received; Set;} Public String Message {get} Set;}} Public Category UserResponse: Responsebase {Ienumerable & lt; User & gt; Users}; Now, if you have any errors:
returns Jason (new responsebase) {successful = false, message = "your error"}
returns Jason (new user response) {successful = true, user = usage Actor}); If you want to manually craft JSON, then just:
Comments
Post a Comment