I have the following structure:
- WebService - get the data from database and return the list of persons
- ASP.NET MVC application - uses web service from 1).
There's a method in HomeControler:
public JsonResult GetDbData()
{
WebService1SoapClient client = new WebService1SoapClient();
List<Person> lstPersons = client.GetPersons();
return Json(lstPersons, JsonRequestBehavior.AllowGet);
}
I'd like to display the list of persons in Index.cshtml view using jQuery Ajax call in this manner:
<div>
<div id="div3">Database data.</div>
</div>
<input id="btnGetDBData" type="button" value="GetDBData" />
$('#btnGetDBData').click(function () {
$.ajax({
url: "/Home/GetDbData",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$("#div3").html(data);
},
error: function (xhr, status) {
alert(status);
}
});
});
But, it's not working.
I'm new in jQuery and need some kind of table or template or something like repeater that can display the list or table structure.
The Person class looks as following:
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
I need to display the list of persons in Html table.