- Posted On 14 April 2016
- By
- In Programming

Hello friend, In this short post I will share how to post JSON model as a string to the action method of the controller in MVC using jQuery Ajax.
Suppose you wanted to save user preference as JSON string in one of the column of your table in database, then you can write a action method like following.
[HttpPost] public void SaveSetup(string jsonString) { //code to save setting in databse }
And you need to write code like following on some button click to post your JSON model to above action method.
var jsonModel = "your json model"; $.ajax({ type: 'POST', data: JSON.stringify({ jsonString: JSON.stringify(jsonModel) }), contentType: "application/json; charset=utf-8", url: "/User/SaveSetup/", dataType: 'json', success: function (data) { alert('saved'); } });
That's it, with above code you can successfully post JSON model as string.
Thanks. Do share your thoughts in comment section below.
- Tags :
- MVC
- jQueryJavascript

Typewriter - Automatic TypeScript Template generation from C# classes in Visual Studio
Typewriter, an extension for visual studio that generates TypeScript files from C# code files using TypeScript templates. Convert your C# model classes to TypeScript automatically.

How to call click or any event only once in jQuery
Know how to execute an click event or any event only once for any element in jQuery. Perform action only once and even not required to unbind event.

Top 10 Visual Studio things which can boost developers coding speed
Visual Studio 2012 provides some coding features by which you can code faster if use them properly. This post will cover top 10 things among them to boost your development speed.

Copy changed data in table from one database to another in SQL stored procedure
How to copy or merge changed data in table from one database to another having same schema is the topic of this post.

Assembla - Free and private repository to manage your source code online with SVN subversion hosting
With Assembla you can share source code with others online. Free & Private source code repository with SVN Subversion, Git & Perforce Hosting.