将所选值传递给html.actionlink

时间:2015-10-01 15:28:10

标签: c# asp.net-mvc razor

我每月有2个下拉菜单(存储值1到12)和年份:

@Html.DropDownList("Month",ViewData["MonthList"] as SelectList)
@Html.DropDownList("Year", ViewData["YearList"] as SelectList)

我有一个HTML.ActionLink转发到控制器动作,需要Date作为输入:

@Html.ActionLink("Show for This Month", "EntriesInMonth", "Entries"
    , new { date = DateTime.Now }, null)

问题是如何从所选值中创建日期对象,并在点击它时将其传递给ActionLink?

1 个答案:

答案 0 :(得分:2)

您应该使用表单来完成您想要完成的任务。

@using (Html.BeginForm("EntriesInMonth", "Entries"))
{
    @Html.DropDownList("Month",ViewData["MonthList"] as SelectList)
    @Html.DropDownList("Year", ViewData["YearList"] as SelectList)
    <input type="submit" value="Show for This Month">
}