[HttpPost]
public JsonResult searchByName(string name)
{
dbCRMEntities dbx = new dbCRMEntities();
var test = name;
var names = dbx.CONTACTS.Where(chk => name == chk.NAME);
return this.Json(names, JsonRequestBehavior.AllowGet);
}
This method is returning the data in this format:
[
{
"CONTACT_ID": 37,
"NAME": "umair",
"JOB_TITLE": "internee",
"COMPANY": "fastservices",
"PHONE": "244",
"EMAIL": "[email protected]",
"WEB": "alskdjg",
"ADDRESS": "lahore",
"STATUS": "Inactive",
"TAGS": "sdf",
"LEAD_SOURCE": "partner",
"BACKGROUND": "skldjga",
"OWNER": "a",
"BIRTHDAY": "2014-12-18",
"EntityState": 2,
"EntityKey": {
"EntitySetName": "CONTACTS",
"EntityContainerName": "dbCRMEntities",
"EntityKeyValues": [
{
"Key": "CONTACT_ID",
"Value": 37
}
],
"IsTemporary": false
}
}
]
and my jquery method is:
$(document).ready(function () {
$("#btn1").click(function () {
var name = $("#search").val();
//name = "ali";
alert(name);
$.post("/Status/searchByName", { name: name }, function (data) {
document.write(data);
$.each(data, function (key, value) {
});
}, "text");
});
});
I want to obtain data in tabular form in the view. Please guide me
tdin your loop, appending the value of the property in to it - that hard part is already done.document.writeit will wipe out the whole page when used after onload has occured. Log to console instead usingconsole.log(data)