Jquery 无法在mvc中将Html表绑定到json
我使用以下过程从控制器获取信息,但没有获取任何信息Jquery 无法在mvc中将Html表绑定到json,jquery,json,asp.net-mvc,Jquery,Json,Asp.net Mvc,我使用以下过程从控制器获取信息,但没有获取任何信息 添加控制器类 HomeController.cs: public class HomeController: Controller { // GET: Home public ActionResult Index() { return View(); }
public class HomeController: Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpGet]
public JsonResult EmpDetails()
{
//Creating List
List < Employee > ObjEmp = new List < Employee > ()
{
new Employee
{
Id = 1, Name = "Vithal Wadje", City = "Latur", Address = "Kabansangvi"
},
new Employee
{
Id = 2, Name = "Sudhir Wadje", City = "Mumbai", Address = "Kurla"
}
};
return Json(ObjEmp, JsonRequestBehavior.AllowGet);
}
}
<script>
$(document).ready(function () {
//Call EmpDetails jsonResult Method
$.getJSON("Home/EmpDetails",
function (json) {
var tr;
for (var i = 0; i < json.length; i++) {
tr = $('<tr/>');
tr.append("<td>" + json[i].Id + "</td>");
tr.append("<td>" + json[i].Name + "</td>");
tr.append("<td>" + json[i].City + "</td>");
tr.append("<td>" + json[i].Address + "</td>");
$('table').append(tr);
}
});
});
</script>
<table class="table table-bordered table-condensed table-hover table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>City</th>
<th>Address</th>
</tr>
</thead>
<tbody></tbody>
</table>
@{
ViewBag.Title = "www.compilemode.com";
}
<div style="margin-top:20px">
@Html.Partial("EmpDetails");
</div>
公共类HomeController:控制器
{
//到家
公共行动结果索引()
{
返回视图();
}
[HttpGet]
公共JsonResult EmpDetails()
{
//创建列表
列表ObjEmp=新列表()
{
新员工
{
Id=1,Name=“Vithal Wadje”,City=“Latur”,Address=“Kabansangvi”
},
新员工
{
Id=2,Name=“Sudhir Wadje”,City=“孟买”,Address=“库尔拉”
}
};
返回Json(ObjEmp,JsonRequestBehavior.AllowGet);
}
}
public class HomeController: Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpGet]
public JsonResult EmpDetails()
{
//Creating List
List < Employee > ObjEmp = new List < Employee > ()
{
new Employee
{
Id = 1, Name = "Vithal Wadje", City = "Latur", Address = "Kabansangvi"
},
new Employee
{
Id = 2, Name = "Sudhir Wadje", City = "Mumbai", Address = "Kurla"
}
};
return Json(ObjEmp, JsonRequestBehavior.AllowGet);
}
}
<script>
$(document).ready(function () {
//Call EmpDetails jsonResult Method
$.getJSON("Home/EmpDetails",
function (json) {
var tr;
for (var i = 0; i < json.length; i++) {
tr = $('<tr/>');
tr.append("<td>" + json[i].Id + "</td>");
tr.append("<td>" + json[i].Name + "</td>");
tr.append("<td>" + json[i].City + "</td>");
tr.append("<td>" + json[i].Address + "</td>");
$('table').append(tr);
}
});
});
</script>
<table class="table table-bordered table-condensed table-hover table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>City</th>
<th>Address</th>
</tr>
</thead>
<tbody></tbody>
</table>
@{
ViewBag.Title = "www.compilemode.com";
}
<div style="margin-top:20px">
@Html.Partial("EmpDetails");
</div>
$(文档).ready(函数(){
//调用EmpDetails jsonResult方法
$.getJSON(“主/主详细信息”,
函数(json){
var-tr;
对于(var i=0;i
public class HomeController: Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpGet]
public JsonResult EmpDetails()
{
//Creating List
List < Employee > ObjEmp = new List < Employee > ()
{
new Employee
{
Id = 1, Name = "Vithal Wadje", City = "Latur", Address = "Kabansangvi"
},
new Employee
{
Id = 2, Name = "Sudhir Wadje", City = "Mumbai", Address = "Kurla"
}
};
return Json(ObjEmp, JsonRequestBehavior.AllowGet);
}
}
<script>
$(document).ready(function () {
//Call EmpDetails jsonResult Method
$.getJSON("Home/EmpDetails",
function (json) {
var tr;
for (var i = 0; i < json.length; i++) {
tr = $('<tr/>');
tr.append("<td>" + json[i].Id + "</td>");
tr.append("<td>" + json[i].Name + "</td>");
tr.append("<td>" + json[i].City + "</td>");
tr.append("<td>" + json[i].Address + "</td>");
$('table').append(tr);
}
});
});
</script>
<table class="table table-bordered table-condensed table-hover table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>City</th>
<th>Address</th>
</tr>
</thead>
<tbody></tbody>
</table>
@{
ViewBag.Title = "www.compilemode.com";
}
<div style="margin-top:20px">
@Html.Partial("EmpDetails");
</div>
@{
ViewBag.Title=“www.compilemode.com”;
}
@Html.Partial(“EmpDetails”);