【发布时间】:2014-12-13 00:25:50
【问题描述】:
在阅读了有关如何使用 linq 填充列表框的几天后,我完全不知道我必须做些什么才能完成这项工作。我知道我必须有一个视图模型或类似的东西,但由于我不能在同一个视图中引用 2 个模型,所以我不知道该怎么做。
这是我的模型
public class ABC
{
public int a { get; set; }
public int b { get; set; }
public int c { get; set; }
public string d { get; set; }
public string Type { get; set; }
public int ID { get; set; }
public class ABCDBContext : DbContext
{
public DbSet<ABC> ABCs { get; set; }
}
}
public class ABCModel
{
public string type{ set; get; }
public List<ABC> ABCs { set; get; }
}
控制器我知道我遗漏了很多东西,但我不知道如何使用该 linq 查询填充列表,也不知道如何在不使用 beginform 的情况下从视图中调用此控制器(我将有超过 1 个列表框这种形式)
public ActionResult GetStuff()
{
var Types = from m in db.ABCs
select m.Type.Distinct();
return View(Types);
}
然后在我看来,我必须拥有 @model IEnumerable 所以我可以在该页面上显示表 abc 的所有内容。
那么,我可以创建一个填充 lsitbox 的视图模型吗(我需要用 abc 具有的参数填充至少 6 个,以便用户可以使用这些值搜索 abcs,但我想如果我能理解如何做 1 我可以为 6) 做我想要的并且允许我显示 abc 的条目吗?
这就是观点(我知道它有很多问题,但它只是举个例子)
@using (Html.BeginForm("getSelectedValues", "ABC", FormMethod.Get))
{
Type:@Html.DropDownList()
a:@Html.DropDownList()
b:@Html.DropDownList()
//and so on
<input type="submit" value="Filter" />
}
请原谅我对我错过的任何方面的无知,但我是 asp net mvc 5 的新手,如果有人可以指导我或向我发送关于我必须做什么的指南,我将不胜感激。
【问题讨论】:
-
您应该使用视图模型来表示您想要显示和编辑的内容,但不清楚您实际编辑的是什么以及您想要显示下拉列表的哪些属性?
标签: c# asp.net asp.net-mvc linq