我有一个包含DropDownList
大量项目的 MVC 网页。每个项目都是我的一个对象Database
,代表磁盘上的一个文件。
我的对象类:
namespace CapturesMVC.Models
public class Capture : IEquatable<Capture>
{
public int id { get; set; }
[Display(Name = "File Name")]
public string fileName { get; set; }
[Display(Name = "Browser")]
public string browser { get; set; }
[Display(Name = "Mobile")]
public string mobile { get; set; }
[Display(Name = "Protocol")]
public string protocol_site { get; set; }
public string family { get; set; }
public sealed override bool Equals(object other)
{
return Equals(other as Capture);
}
public bool Equals(Capture other)
{
if (other == null)
{
return false;
}
else
{
return this.protocol_site == other.protocol_site;
}
}
public override int GetHashCode()
{
return protocol_site.GetHashCode();
}
}
CaptureDBContext 类:
namespace CapturesMVC.Models
public class CaptureDBContext : DbContext
{
public DbSet<Capture> Captures { get; set; }
}
这是我的控制器:
[HttpPost]
public ActionResult Index(string File)
{
var list = db.Captures.Where(x => x.protocol== File).ToArray();
ViewBag.Files = list;
return View();
}
索引.cshtml:
@using (Html.BeginForm())
{
<div>
@Html.DropDownList("File", new SelectList(ViewBag.Files, "protocol_site", "protocol_site"), "Select webmail site", new { style = "vertical-align:middle;" })
<button type="submit">Select</button>
</div>
}
</body>
从我的项目中选择一个项目DropDownList
并点击按钮后,将Index
执行该操作并返回与我的对象属性之一匹配的对象列表以及我想在列表中显示在我的网页上的该列表,但目前的情况是该列表是插入我的DropDownList
.