我有动态webgrid,我只想搜索所有列。但我需要Jquery代码 我尝试2.控制器只返回视图,但它没有运行
我的控制器:
<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
用jquery给出属性:
<HttpPost()>
Function NewGrid(columnName As String, columnValue As String) As JsonResult
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()
'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.GridSqlQuery = columnSql
ViewBag.OL = data
Return Json(data)
End Function
我的观点:
<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
警告çalıştım而不是webgrid更新:
答案 0 :(得分:0)
**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>