Grunf
Grunf

Reputation: 472

returning object as json from mvc, how to display on the view

I have list of objects which are returned from mvc controller as Json. I'm wondering how to display this objects on the view.

function GetTabData(xdata) {
    $.ajax({
        url: ('/Home/GetTabData'),
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify({ id: xdata }),

        success: function (result) {
           /// what to do here? 
        },
        error: function () { alert("error"); }
    });
}

public JsonResult()
{
   ...
   var temp = getMyData...
   return Json(temp, JsonRequestBehavior.AllowGet);   
}

view page

<div id="showContent"> </div>

Upvotes: 1

Views: 3199

Answers (1)

PoulsQ
PoulsQ

Reputation: 2016

Here is the first step you have to do :

success: function (result) {
    /// what to do here? 
    result = jQuery.parseJSON(result);
    /// Exploit your object(s) ;)
},

Look here for more details on the exploitation : http://api.jquery.com/jQuery.parseJSON/

Upvotes: 1

Related Questions