Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 过滤器下拉列表MVC4_Asp.net Mvc_Asp.net Mvc 5 - Fatal编程技术网

Asp.net mvc 过滤器下拉列表MVC4

Asp.net mvc 过滤器下拉列表MVC4,asp.net-mvc,asp.net-mvc-5,Asp.net Mvc,Asp.net Mvc 5,我是MVC新手。我想使用Dropdownlist中的参数筛选我的表: 我的模型: public class Document { [Key] public int MasterAPID { get; set; } public string CompanyID { get; set; } public MasterCompany MasterCompany { get; set; } public string Year { get; set; }

我是MVC新手。我想使用Dropdownlist中的参数筛选我的表:

我的模型:

public class Document
{
    [Key]
    public int MasterAPID { get; set; }
    public string CompanyID { get; set; }
    public MasterCompany MasterCompany { get; set; }
    public string Year { get; set; }
    public string Month { get; set; }
    public string DocumentNumber { get; set; }
}

public class MasterCompany
{
    [Key]
    public string CompanyID { get; set; }
    public string CompanyName { get; set; }
}
我的控制器:

private IRMAContext db = new IRMAContext();

// GET: MasterAPs
public ActionResult Index()
{
    ViewBag.CompanyID = new SelectList(db.MasterCompanies, "CompanyID", "CompanyName");

    var masterAPs = db.MasterAPs.Include(m => m.MasterCompany);
    return View(masterAPs.ToList());
}
我的看法是:

@Html.DropDownList("CompanyID", null, htmlAttributes: new { @class = "form-control" })
@Html.DropDownList("oYear", Enumerable.Range(DateTime.Now.Year, 10).Select(x => new SelectListItem { Text = x.ToString() }), "Select Year", new { @class = "form-control" })
@Html.DropDownList("oMonth", Enumerable.Range(1, 12).Select(x => new SelectListItem { Text = x.ToString("00") }), "Select Month", new { @class = "form-control" })
<br>
<button type="submit">View</button>

<table>
    <tr>
        <th>
           @Html.DisplayNameFor(model => model.DocumentNumber)
        </th>
    </tr>
</table>
@Html.DropDownList(“CompanyID”,null,htmlAttributes:new{@class=“form control”})
@DropDownList(“oYear”,Enumerable.Range(DateTime.Now.Year,10)。选择(x=>new SelectListItem{Text=x.ToString()}),“选择年份”,新建{@class=“form control”})
@DropDownList(“oMonth”,Enumerable.Range(1,12)。选择(x=>newselectListItem{Text=x.ToString(“00”),“选择月份”,新建{@class=“form control”})

看法 @DisplayNameFor(model=>model.DocumentNumber)
因此,在表本身上,我不会显示这3个参数。只有
DocumentNumber
字段。当用户选择
公司
,然后单击查看按钮时,表格将自动仅显示基于所选参数的数据。

我怎样才能做到这一点?

非常感谢。

您可以在控制器上添加另一个操作,以及与该操作匹配的另一个视图。例如:

// GET: Detials
public ActionResult Details(int companyId)
{
ViewBag.CompanyID = new SelectList(db.MasterCompanies, "CompanyID", "CompanyName");

var specificCompany = db.MasterAPs.Include(m => m.MasterCompany).Where(c => c.Id == companyId);
return View(specificCompany);
}

并根据需要使用传递的数据编辑新的Details.cshtml。

我应该在按钮视图上放置什么?您可以放置