Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.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
C# 如何使用asp.net mvc 3填充jqgrid_C#_Jquery_Asp.net_Asp.net Mvc_Jqgrid - Fatal编程技术网

C# 如何使用asp.net mvc 3填充jqgrid

C# 如何使用asp.net mvc 3填充jqgrid,c#,jquery,asp.net,asp.net-mvc,jqgrid,C#,Jquery,Asp.net,Asp.net Mvc,Jqgrid,我正在尝试使用[HttPost]控制器方法中的数据填充jqgrid 我的控制器是这样的 Public ActionResult Index() { SearchModel sm = new SearchModel(); // gets specific data from sm here return View(sm); } [HttpPost] Public ActionResult Index(SearchModel sm) { // does some stuff

我正在尝试使用[HttPost]控制器方法中的数据填充jqgrid

我的控制器是这样的

Public ActionResult Index()
{
   SearchModel sm = new SearchModel();
   // gets specific data from sm here
   return View(sm);
}

[HttpPost]
Public ActionResult Index(SearchModel sm)
{
   // does some stuff with the entered data from the form to return search results
   // not sure what exactly to do here....

}
我的表单如下所示:

@model SearchModel

@{
   //layout stuff and other script links are here
}

{Html.EnableClientValidation();}
@using (Html.BeginForm("Index", "Page",
                 FormMethod.Post, new { id = "search-form" }))
{

   //I have the form and post data here

}

@if (Model.SearchRecords != null)
{
    Html.RenderPartial("SearchRecordsPartial");
}
@model SearchModel

<div>

    <table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
    <div id="pager" class="scroll" style="text-align:center;"></div>

</div>
我的jqgrid所在部分如下所示:

@model SearchModel

@{
   //layout stuff and other script links are here
}

{Html.EnableClientValidation();}
@using (Html.BeginForm("Index", "Page",
                 FormMethod.Post, new { id = "search-form" }))
{

   //I have the form and post data here

}

@if (Model.SearchRecords != null)
{
    Html.RenderPartial("SearchRecordsPartial");
}
@model SearchModel

<div>

    <table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
    <div id="pager" class="scroll" style="text-align:center;"></div>

</div>
任何关于如何做到这一点的帮助或链接都将非常棒。我尝试过在线搜索帮助,有很多不同的文章,但我似乎找不到一篇使用asp.NETMVC从表单数据填充jqgrid的文章


谢谢,

如果您只想在网格中显示数据,您可以使用以下代码,但如果您想使用添加、编辑、删除、筛选、排序等功能,此代码还不够,请详细说明要求

[HttpPost]
Public ActionResult Index(SearchModel sm)
{
        List<Object> returnData = new List<Object>();
        returnData.Add(new { id = 1, cell = new string[] {"Id1","Votes1","Title1"} });
        returnData.Add(new { id = 2, cell = new string[] {"Id2","Votes2","Title2"} });
        returnData.Add(new { id = 3, cell = new string[] {"Id3","Votes3","Title3"} });
        var result = new { total = 1, page = 1, records = 3, rows = returnData };
        return Json(result, JsonRequestBehavior.AllowGet);
}    
[HttpPost]
公共行动结果索引(SearchModel sm)
{
List returnData=新列表();
Add(新的{id=1,cell=newstring[]{“Id1”,“Votes1”,“Title1”});
Add(新的{id=2,cell=newstring[]{“Id2”,“Votes2”,“Title2”});
Add(新的{id=3,cell=newstring[]{“Id3”,“Votes3”,“Title3”});
var result=new{total=1,page=1,records=3,rows=returnData};
返回Json(结果,JsonRequestBehavior.AllowGet);
}    
这里有一个很好的链接:

我正在组装一个MVC4 jqGrid,这对我帮助很大

编辑:
只是为了增加一点颜色,我认为您不希望在索引操作中返回网格结果。jQgrid将在需要加载新数据时调用您指定的url-作为排序、搜索、刷新等的结果。。。如果你看一看我链接的文章,它会更详细地介绍这篇文章。

你应该在控制器操作中传递排序和分页参数

[HttpPost]
public ActionResult ListCustomer(string sidx, string sord, int page, int rows)
{
  // return the json data
}