Swa*_*p56 8 c# asp.net-mvc asp.net-mvc-2
我正在将经典ASP中的搜索应用程序移植到ASP.NET MVC2.其中一个hte页面是一个动态填充的搜索表单,它分为4个类别,每个类别有2行.
客户端可以取消选中每个类别的选项.发生这种情况时,每个类别都是从上到下,从左到右动态重新填充.编程Classic ASP版本的人设置了一个通过数据库搜索的子程序(每个搜索字段都有一个布尔字段),然后返回一个数组.然后他接受了数组并调用了另一个循环数组的子程序,然后生成了每个类别.
现在,我唯一能想到的是创建一个模型,其中包含每个类别的方法,每个类别都返回一个List.一个简单的例子是:
class SearchPageOrganizer {
// Declare SearchFields object
private SearchFields fields;
// Contructor; instantiates SearchFields object
public SearchPageOrganizer(SearchFields searchFields) {
this.fields = searchFields;
}
// Gets a list of fields active in the characteristics category
public List<String> GetCharactersticsList() {
List<String> list = new List<String>();
// Check if the Color field is active
if (fields.Color) {
list.Add("Color");
}
// Check if the Size field is active
if (fields.Size) {
list.Add("Size");
}
// Return the list
return list;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我可以做的是根据每行的大小拆分列表,然后遍历每个列表并调用一个能够根据名称参数动态呈现HTML的用户控件.
这种技术的问题在于,由于一些奇怪的原因,我觉得我不是以最简单的方式做这件事.对于任何阅读此内容的人,您是否有更简单的方法来实现此目的?
谢谢!
需要时在客户端使用 JavaScript (jQuery) 添加列表怎么样?可以使用 Ajax 调用来填充数据。一旦所有字段都已填写并且用户提交,操作方法就可以获取所有传入参数并基于该参数执行搜索。