Quick Way To Get One Record of Data Using Ajax and Hashtable

0 comments

in controller        


public ActionResult HelpText(int ID) {            
	var help = Models.HelpText.LoadID(ID); Hashtable data = null;            
	if (help != null ) {                
	data = help.GetHashtable();       
	}
		
	//mess with the data             
	data["BodyTextHtml"]=data["BodyTextHtml"].ToString().Replace("attachments/pics\\","attachments/pics/");
	var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();             
	return Json(serializer.Serialize(data));         
}   



in ui       

var qs = "id=" + escape(helpID) + "";
var url = websiteBaseUrl + "Common/HelpText/";
$.ajax({            
    type: "POST",
    url: url,
    data: qs,
    dataType: "json",  
    //async: false, //this means wait for each result - comment out to not wait for return
    success: function (msg) {                 
       var obj = $.parseJSON(msg);
       alert( obj.BodyTextHtml );             
    },
    error: function (msg) {                 
       alert("call failed: " + msg.responseText);  //prompt('copy this',url+'?'+qs)
    }         
});


or alternatively in controller        


public ActionResult HelpText(int ID) {            
    var data = help.JsonObject();   // gives you a dictionary

    // you can mess with the data also

    return Json(data);        
}  

Comments


Leave a Comment