Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 无法在mvc中将Html表绑定到json_Jquery_Json_Asp.net Mvc - Fatal编程技术网

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(); }

我使用以下过程从控制器获取信息,但没有获取任何信息

  • 添加控制器类 HomeController.cs:

         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
  • 在主索引视图中调用部分视图EmpDetails 部分查看主索引视图中的详细信息:

         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”);