Javascript Asp.net MVC动态WEBGRID搜索所有列,然后在同一视图中更新WEBGRID
我有动态webgrid,我只想搜索所有列。但是我需要查询代码 我试试看。控制器仅返回视图,但未运行 我的控制器:Javascript Asp.net MVC动态WEBGRID搜索所有列,然后在同一视图中更新WEBGRID,javascript,jquery,html,asp.net,asp.net-mvc,Javascript,Jquery,Html,Asp.net,Asp.net Mvc,我有动态webgrid,我只想搜索所有列。但是我需要查询代码 我试试看。控制器仅返回视图,但未运行 我的控制器: <HttpGet()> Function NewGrid() As ActionResult Dim g As ServiceReference1.Grid = New Grid Dim client As ServiceReference1.Service1Client = New ServiceReference1.Servi
<HttpGet()>
Function NewGrid() As ActionResult
Dim g As ServiceReference1.Grid = New Grid
Dim client As ServiceReference1.Service1Client = New ServiceReference1.Service1Client()
g = client.GetGridInformation("lst_afhFTR")
Dim column As List(Of ServiceReference1.Column)
column = g.columnList.ToList
Dim columnName As List(Of String) = g.columnList.Select(Function(f) f.columnName).ToList()
client.Close()
Dim client3 As ServiceReference1.Service1Client = New ServiceReference1.Service1Client()
Dim result As List(Of Dictionary(Of String, Object)) = client3.GetTableOl(g.gridCode).ToList()
'WebGrid içine gönderilecek data oluşturulması
Dim data = New List(Of ExpandoObject)()
For Each Pairs In result
Dim row = New ExpandoObject()
For Each Pair In Pairs
DirectCast(row, IDictionary(Of String, Object)).Add(Pair.Key, Pair.Value)
Next
data.Add(row)
Next
ViewBag.ColumnList = g.columnList
ViewBag.GridSqlQuery = g.gridCode
Return View(data)
End Function
函数NewGrid()作为ActionResult
Dim g As ServiceReference1.Grid=新网格
作为ServiceReference1.Service1Client的Dim客户端=新的ServiceReference1.Service1Client()
g=客户端.GetGridInformation(“lst_afhFTR”)
Dim列作为列表(服务引用1.列的列表)
column=g.columnList.ToList
Dim columnName As List(字符串的)=g.columnList.Select(函数(f)f.columnName.ToList()
client.Close()
Dim客户端3作为ServiceReference1.Service1Client=新的ServiceReference1.Service1Client()
Dim结果作为列表(字典的(字符串的,对象的))=client3.GetTableOl(g.gridCode.ToList())
“WebGrid içine gönderilecek data oluşturulması
尺寸数据=新列表(扩展对象)()
对于结果中的每一对
尺寸行=新的ExpandooObject()
每对一对
DirectCast(行,IDictionary(字符串,对象)).Add(Pair.Key,Pair.Value)
下一个
data.Add(行)
下一个
ViewBag.ColumnList=g.ColumnList
ViewBag.GridSqlQuery=g.gridCode
返回视图(数据)
端函数
使用jquery-give属性:
函数NewGrid(columnName作为字符串,columnValue作为字符串)作为JsonResult
Dim g As ServiceReference1.Grid=新网格
作为ServiceReference1.Service1Client的Dim客户端=新的ServiceReference1.Service1Client()
g=客户端.GetGridInformation(“lst_afhFTR”)
Dim列作为列表(服务引用1.列的列表)
column=g.columnList.ToList
ViewBag.ColumnList=g.ColumnList
client.Close()
Dim columnSql As String=“从afhFTR\u Fatura中选择*
columnSql=columnSql.ToString()+“其中1=1”
columnSql=columnSql+”和“+columnName+”类似“%”“+columnValue.ToString()+“%”
Dim客户端3作为ServiceReference1.Service1Client=新的ServiceReference1.Service1Client()
Dim结果作为列表(字典的(字符串的,对象的))=client3.GetSearchData(columnSql).ToList()
“WebGrid içine gönderilecek data oluşturulması
尺寸数据=新列表(扩展对象)()
对于结果中的每一对
尺寸行=新的ExpandooObject()
每对一对
DirectCast(行,IDictionary(字符串,对象)).Add(Pair.Key,Pair.Value)
下一个
data.Add(行)
下一个
ViewBag.GridSqlQuery=columnSql
ViewBag.OL=数据
返回Json(数据)
端函数
我的看法是:
<h2>NewGrid</h2>
<div>
<table class="table table-bordered">
@*<tr style="visibility:hidden"><td><input id="Hidden1" type="hidden" value=@ViewBag.Code.ToString() /></td></tr>*@
<tr>
@For Each col As ServiceReference1.Column In ViewBag.ColumnList
@<td>
<input class="search" id=@col.columnName type="text" value="gün" name=@col.columnName style="border-width:1px;width:@col.columnWidth.ToString()px;" />
</td>
Next
</tr>
</table>
</div>
<div id="olur">
@Code
Dim grid As WebGrid = New WebGrid(Model)
Dim columnsL As List(Of WebGridColumn) = New List(Of WebGridColumn)
For Each col As ServiceReference1.Column In ViewBag.ColumnList
columnsL.Add(grid.Column(columnName:=col.columnName, header:=col.columnCaptionValue, format:=Function(item) New MvcHtmlString("<div style='width:" + col.columnWidth.ToString() + "px;'>" +
item(col.columnCaptionValue) +
"</div>")))
Next
@grid.GetHtml(tableStyle:="table table-striped table-bordered", columns:=columnsL)
End Code
@*, columnSql:"@ViewBag.GridSqlQuery"*@
</div>
@ViewBag.GridSqlQuery
<script type="text/javascript">
$('body').on('keyup', '.search', function (event) {
if (event.keyCode == 13) {
alert('enter key');
var data = { columnName: $(this).attr('id'), columnValue: $(this).val()};
$.ajax({
url: "/Home/NewGrid",
type: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(data),
success: function (data) {
alert("çalıştım"+data);
}
});
}
});
</script
NewGrid
@**@
@对于ViewBag.ColumnList中的每个列作为服务引用1.列
@
下一个
@代码
将网格尺寸调整为WebGrid=新的WebGrid(模型)
Dim columnsL As List(属于WebGridColumn)=新列表(属于WebGridColumn)
对于ViewBag.ColumnList中的每个列作为服务引用1.列
columnsL.Add(grid.Column)(columnName:=col.columnName,header:=col.columnCaptionValue,format:=函数(项)New MvcHtmlString(“”)+
项目(列标题值)+
"")))
下一个
@GetHtml(表样式:=“表条带边框的表”,列:=columnsL)
结束代码
@*,columnSql:“@ViewBag.GridSqlQuery”*@
@ViewBag.GridSqlQuery
$('body').on('keyup','search',函数(事件){
如果(event.keyCode==13){
警报(“输入键”);
var data={columnName:$(this.attr('id'),columnValue:$(this.val()};
$.ajax({
url:“/Home/NewGrid”,
类型:“POST”,
数据类型:“json”,
contentType:“应用程序/json”,
数据:JSON.stringify(数据),
成功:功能(数据){
警报(“çalıştım”+数据);
}
});
}
});
**我终于找到了答案,但答案很简单
>
>我添加部分视图**
**
函数PartialGrid(columnName作为字符串,columnValue作为字符串)作为ActionResult
Dim g As ServiceReference1.Grid=新网格
作为ServiceReference1.Service1Client的Dim客户端=新的ServiceReference1.Service1Client()
g=客户端.GetGridInformation(“lst_afhFTR”)
Dim列作为列表(服务引用1.列的列表)
column=g.columnList.ToList
ViewBag.ColumnList=g.ColumnList
client.Close()
Dim columnSql As String=“从afhFTR\u Fatura中选择*
columnSql=columnSql.ToString()+“其中1=1”
columnSql=columnSql+”和“+columnName+”类似“%”“+columnValue.ToString()+“%”
Dim客户端3作为ServiceReference1.Service1Client=新的ServiceReference1.Service1Client()
Dim结果作为列表(字典的(字符串的,对象的))=client3.GetSearchData(columnSql).ToList()
尺寸数据=新列表(扩展对象)()
对于结果中的每一对
尺寸行=新的ExpandooObject()
每对一对
DirectCast(行,IDictionary(字符串,对象)).Add(Pair.Key,Pair.Value)
下一个
data.Add(行)
下一个
返回部分视图(数据)
端函数
结束局部视图:
@代码
将网格尺寸调整为WebGrid=新的WebGrid(模型)
Dim columnsL As List(属于WebGridColumn)=新列表(属于
<h2>NewGrid</h2>
<div>
<table class="table table-bordered">
@*<tr style="visibility:hidden"><td><input id="Hidden1" type="hidden" value=@ViewBag.Code.ToString() /></td></tr>*@
<tr>
@For Each col As ServiceReference1.Column In ViewBag.ColumnList
@<td>
<input class="search" id=@col.columnName type="text" value="gün" name=@col.columnName style="border-width:1px;width:@col.columnWidth.ToString()px;" />
</td>
Next
</tr>
</table>
</div>
<div id="olur">
@Code
Dim grid As WebGrid = New WebGrid(Model)
Dim columnsL As List(Of WebGridColumn) = New List(Of WebGridColumn)
For Each col As ServiceReference1.Column In ViewBag.ColumnList
columnsL.Add(grid.Column(columnName:=col.columnName, header:=col.columnCaptionValue, format:=Function(item) New MvcHtmlString("<div style='width:" + col.columnWidth.ToString() + "px;'>" +
item(col.columnCaptionValue) +
"</div>")))
Next
@grid.GetHtml(tableStyle:="table table-striped table-bordered", columns:=columnsL)
End Code
@*, columnSql:"@ViewBag.GridSqlQuery"*@
</div>
@ViewBag.GridSqlQuery
<script type="text/javascript">
$('body').on('keyup', '.search', function (event) {
if (event.keyCode == 13) {
alert('enter key');
var data = { columnName: $(this).attr('id'), columnValue: $(this).val()};
$.ajax({
url: "/Home/NewGrid",
type: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(data),
success: function (data) {
alert("çalıştım"+data);
}
});
}
});
</script
**I find at last but answer is rather easy
>
> I add partial view **
**
Function PartialGrid(columnName As String, columnValue As String) As ActionResult
Dim g As ServiceReference1.Grid = New Grid
Dim client As ServiceReference1.Service1Client = New ServiceReference1.Service1Client()
g = client.GetGridInformation("lst_afhFTR")
Dim column As List(Of ServiceReference1.Column)
column = g.columnList.ToList
ViewBag.ColumnList = g.columnList
client.Close()
Dim columnSql As String = "select * from afhFTR_Fatura"
columnSql = columnSql.ToString() + " where 1 = 1"
columnSql = columnSql + " and " + columnName + " Like '%" + columnValue.ToString() + "%'"
Dim client3 As ServiceReference1.Service1Client = New ServiceReference1.Service1Client()
Dim result As List(Of Dictionary(Of String, Object)) = client3.GetSearchData(columnSql).ToList()
Dim data = New List(Of ExpandoObject)()
For Each Pairs In result
Dim row = New ExpandoObject()
For Each Pair In Pairs
DirectCast(row, IDictionary(Of String, Object)).Add(Pair.Key, Pair.Value)
Next
data.Add(row)
Next
Return PartialView(data)
End Function
End Partial View:
@Code
Dim grid As WebGrid = New WebGrid(Model)
Dim columnsL As List(Of WebGridColumn) = New List(Of WebGridColumn)
For Each col As ServiceReference1.Column In ViewBag.ColumnList
columnsL.Add(grid.Column(columnName:=col.columnName, header:=col.columnCaptionValue, format:=Function(item) New MvcHtmlString("<div style='width:" + col.columnWidth.ToString() + "px;'>" +
item(col.columnCaptionValue) +
"</div>")))
Next
@grid.GetHtml(tableStyle:="table table-striped table-bordered", columns:=columnsL)
End Code
<h1>Partial view</h1>
Then update my script code :
<script type="text/javascript">
$('body').on('keyup', '.search', function (event) {
if (event.keyCode == 13) {
alert('enter key');
var data = { columnName: $(this).attr('id'), columnValue: $(this).val()};
$.ajax({
url: '/Home/PartialGrid',
data: JSON.stringify(data),
cache: false,
type: "POST",
contentType: "application/json",
dataType: "html",
success: function (data) {
$("#olur").html(data);
}
});
}
});
</script>