在ASP.NET MVC中过滤下拉列表中的表数据 [英] Filtering table data on drop down list change in ASP.NET MVC

查看:87
本文介绍了在ASP.NET MVC中过滤下拉列表中的表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图根据下拉列表中更改的选项过滤html表格中的数据。我能够在a中显示页面中的数据,并且还能够传递下拉值。但不太确定如何重新绑定

数据。有人请帮助我们将非常感谢。



谢谢,

Palash

解决方案

我是JQuery Ajax的新手。下拉选择更改时,我不确定如何重新绑定数据表。我可以绑定相同的视图吗?我试过部分渲染,我不清楚理解,不工作。请告知您是否有任何示例代码或者您是否有任何示例代码将受到高度赞赏。



以下代码简介:

--- ----------------

我绑定下拉列表并在Index()方法中查看。 DDL来自枚举类模型,我构建了一个提供List< person>的dll Business。我绑定表数据。我尝试在UpdateIndex()上重新绑定。我可以通过参数race传递ddl选项,但linq无效。



控制器代码:

===== ==========

public ActionResult Index()

{

List< SelectListItem> selectListItem = new List< SelectListItem>();

DropDownModel dropDownModel = new DropDownModel();



dropDownModel.id =(int)enumRace .eRace.Angles;

dropDownModel.Value = enumRace.eRace.Angles.ToString();



selectListItem.Add(new SelectListItem( ){Value = dropDownModel.Value,Text = dropDownModel.id.ToString()});



dropDownModel.id =(int)enumRace.eRace.Saxons;

dropDownModel.Value = enumRace.eRace.Saxons.ToString();



selectListItem.Add(new SelectListItem(){Value = dropDownModel。 Value,Text = dropDownModel.id.ToString()});



dropDownModel.id =(int)enumRace.eRace.Jutes;

dropDownModel.Value = enumRace.eRace.Jutes.ToString();



selectListItem.Add(new SelectListItem(){Value = dropDownModel.Value ,Text = dropDownModel.id.ToString()});



dropDownModel.id =(int)enumRace.eRace.Asians;

dropDownModel.Value = enumRace.eRace.Asians.ToString();



selectListItem.Add(new SelectListItem(){Value = dropDownModel.Value,Text = dropDownModel.id .ToString()});



ViewBag.DropDownList = new SelectList(selectListItem,Text,Value);



RaceModel rcModel = new RaceModel();

List< businessobject.person> people = rcModel.personCollection;



ViewBag.Peoples = people.Where(a => a.Age%2 == 0).OrderBy(o => o.Age).ToList();



返回查看();

}



public ActionResult UpdateIndex(string race)

{

RaceModel rcModel = new RaceModel();

ViewBag.Peoples = null ;

列表< businessobject.person> people = rcModel.personCollection;

ViewBag.Peoples = people.Where(a => a.Age.ToString()== race).ToList();

返回查看(比赛);



}



}





================================== ================



查看代码:

======= ====



@model RaceDB.Models.RaceModel



@ {

ViewBag.Title =索引;

}

< script src =〜/ Scripts / jquery-1.5.1.min.jstype = text / javascript>< / script>

< script src =http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min。 js,type =text / javascript>< / script>

< script type =text / javascript>


< blockquote>(document).ready(function(){


(#RaceDropDownList)。change(function(){


Hi,

I was trying to filter data on html table based on the selection changed in drop down list. I was able to show data in page in a and also able to pass the drop down value. But not quite sure how to rebind that

data.Could someone please help will be highly appreciated.

Thanks,
Palash

解决方案

I am new in JQuery Ajax. I am not sure how to rebind data table when drop down selection changed. Can I bind on same view? Also partial rendering I tried, which I am not clear understanding, not working. Please advise if you have any or if you have any sample code would be highly appreciated.

Brief of bellow code:
-------------------
I bind drop down and view in Index() method. DDL is getting from enum class model and I build a dll Business that supplies List<person> that I bind on table data. I tried rebinding on UpdateIndex(). I am able to pass ddl selection through parameter "race" but linq is not working.

Controller Code:
===============
public ActionResult Index()
{
List<SelectListItem> selectListItem = new List<SelectListItem>();
DropDownModel dropDownModel = new DropDownModel();

dropDownModel.id = (int)enumRace.eRace.Angles;
dropDownModel.Value = enumRace.eRace.Angles.ToString();

selectListItem.Add(new SelectListItem() { Value = dropDownModel.Value, Text = dropDownModel.id.ToString() });

dropDownModel.id = (int)enumRace.eRace.Saxons;
dropDownModel.Value = enumRace.eRace.Saxons.ToString();

selectListItem.Add(new SelectListItem() { Value = dropDownModel.Value, Text = dropDownModel.id.ToString() });

dropDownModel.id = (int)enumRace.eRace.Jutes;
dropDownModel.Value = enumRace.eRace.Jutes.ToString();

selectListItem.Add(new SelectListItem() { Value = dropDownModel.Value, Text = dropDownModel.id.ToString() });

dropDownModel.id = (int)enumRace.eRace.Asians;
dropDownModel.Value = enumRace.eRace.Asians.ToString();

selectListItem.Add(new SelectListItem() { Value = dropDownModel.Value, Text = dropDownModel.id.ToString() });

ViewBag.DropDownList = new SelectList(selectListItem, "Text", "Value");

RaceModel rcModel = new RaceModel();
List<businessobject.person> people = rcModel.personCollection;

ViewBag.Peoples = people.Where(a => a.Age % 2 == 0).OrderBy(o => o.Age).ToList();

return View();
}

public ActionResult UpdateIndex(string race)
{
RaceModel rcModel = new RaceModel();
ViewBag.Peoples = null;
List<businessobject.person> people = rcModel.personCollection;
ViewBag.Peoples = people.Where(a => a.Age.ToString() == race).ToList();
return View("Race");

}

}


==================================================

View Code:
===========

@model RaceDB.Models.RaceModel

@{
ViewBag.Title = "Index";
}
<script src="~/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js", type="text/javascript"></script>
<script type="text/javascript">


(document).ready(function () {


("#RaceDropDownList").change(function () {


这篇关于在ASP.NET MVC中过滤下拉列表中的表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆