如何根据文本框的值过滤列表
How to filter list according to the value of text box
我是 asp.net 和 c# 的新手。
我需要根据文本框过滤一个列表,然后在网页中展示。所以我在控制器中做了以下操作。
public PartialViewResult GetDetails (int id)
{
List<VoInfoDetail> model = db.VoInfoDetails.ToList();
return PartialView("VoDetails", model);
}
然后我在视图中写下以下内容 jQuery
function getdetails() {
var id = $("#VoNo").val();
$.ajax({
url: "/VoInfoHeaders/GetDetails",
type: "GET",
data: { id: id },
success: function (data) {
$("#VoDetails").html(data);
},
error: function (xhr, status, error) {
alert(xhr.responseText);
}
});
}
如何将参数 (id) 从视图传递到部分视图控制器以根据该值过滤数据。我已经通过了 (id) 但它没有过滤
将 id 作为参数添加到 GetDetails,然后适当地更改您的模型获取
public PartialViewResult GetDetails ( int id )
{
List<VoInfoDetail> model = db.VoInfoDetails.Where( m => condition testing id here ).ToList();
return PartialView("VoDetails", model);
}
I already pass the (id) but it's not filtering
因为你要自己写过滤逻辑,即:
public PartialViewResult GetDetails (int id)
{
List<VoInfoDetail> model = db.VoInfoDetails
.Where(x => x.Id == id)
.ToList();
return PartialView("VoDetails", model);
}
我是 asp.net 和 c# 的新手。
我需要根据文本框过滤一个列表,然后在网页中展示。所以我在控制器中做了以下操作。
public PartialViewResult GetDetails (int id)
{
List<VoInfoDetail> model = db.VoInfoDetails.ToList();
return PartialView("VoDetails", model);
}
然后我在视图中写下以下内容 jQuery
function getdetails() {
var id = $("#VoNo").val();
$.ajax({
url: "/VoInfoHeaders/GetDetails",
type: "GET",
data: { id: id },
success: function (data) {
$("#VoDetails").html(data);
},
error: function (xhr, status, error) {
alert(xhr.responseText);
}
});
}
如何将参数 (id) 从视图传递到部分视图控制器以根据该值过滤数据。我已经通过了 (id) 但它没有过滤
将 id 作为参数添加到 GetDetails,然后适当地更改您的模型获取
public PartialViewResult GetDetails ( int id )
{
List<VoInfoDetail> model = db.VoInfoDetails.Where( m => condition testing id here ).ToList();
return PartialView("VoDetails", model);
}
I already pass the (id) but it's not filtering
因为你要自己写过滤逻辑,即:
public PartialViewResult GetDetails (int id)
{
List<VoInfoDetail> model = db.VoInfoDetails
.Where(x => x.Id == id)
.ToList();
return PartialView("VoDetails", model);
}