InCommand InCommand - 2 years ago 189
Javascript Question

Display json data from Ajax and display on JQuery Dialog with in MVC3 View

I have the Following ActionResult in a Controller. it returns a row of data(such as id, name, city etc) from database depending on the ID

public ActionResult Get(Guid Id)
Ref imp = ReadRepository.GetById(refImpId);
var ijson = new JsonResult() { Data = imp.ToJson() };
return ijson;

the Following is the JQuery and Ajax for Jquery Dialog.

$(".ImpList").click(function (e) {

// get the imp id
var refImpId = $(this).next('#impId').val();
var impgeturl = $('#impgeturl').val();
var imptoedit = null;

type: 'post',
url: impgeturl,
data: '{ "refImpId": "' + refImpId + '" }',
contentType: "application/json; charset=utf-8",
traditional: true,
success: function (data) {
imptoedit = jQuery.parseJSON(data);

width: 350,
height: 220,
modal: true,
draggable: false,
resizable: false,

error: function (request, status, error) {
alert(e); // TODO: need to discuss ajax error handling and form reset strategy.

$("#cancelEditImpBtn").click(function (e) {

$("#saveEditImpBtn").click(function (e) {

I have a Dialog in my View. I need to Display the Json Data into the Jquery dialog. How can i do that?

Answer Source
 //in actuality the json will be parsed here
    var d = '{"id":"1","name":"john","age":26}';
    var json = $.parseJSON(d);
    $("<div/>",{" "+json.age}).appendTo("body");



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download