hi ,
i have json data as shown below and i want to store it in to existing database having predefined schema and i am using MVC 4 and this json result is returned by web service.so can some one help me how to do that.
Advance Thanx
{ 'store':[
{
"StoreID": "1",
"StoreName": "Victoria CWH",
"BrandID": 2,
"ServerHostName": "http://demo3kentico8.raybiztech.com"
}
]}
Tanmay MulePosted Mar 13, 2015, 7:27 AM
decorate ur method with [HttpPost] attribute.
And finally make AJAX Jquery post call to ur Action method along with the json object.
var store = { 'store':[
{
"StoreID": "1",
"StoreName": "Victoria CWH",
"BrandID": 2,
"ServerHostName": "http://demo3kentico8.raybiztech.com"
}
]}
$.ajax(
{
type: "POST",
url: "/controller/action",
data: store,
contentType: "application/json; charset=utf-8",
async: false,
},
success: function (data) {
alert('success')
},
error: function () {
alert("Error occured while getting data from server.");
}
}
);
Then write your data strore logic using EF at newly created Action method.
public ActionResult StoreData(StoreModel model)
{
//use model object to store the data in db using EF.
return Json(new {
success=true;
});
}