MVC4:如何将表单参数从视图发送到控制器?

时间:2014-03-13 20:12:53

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4

浏览动作:

public ActionResult Browse(int? Category, string sortOrder, string currentFilter, string searchString, int? page)

我可以使用操作链接发送类别ID

@Html.ActionLink("Name", "Browse", new { sortOrder = ViewBag.NameSortParm, currentFilter=ViewBag.CurrentFilter, Category=ViewBag.CategoryId })

如何将类别ID从表单传递给控制器​​?

<div id="search">
        @using (Html.BeginForm("Browse", "Home", FormMethod.Get))
        {
        @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
        <input type="submit" value="Search" />
        }
        </div>

1 个答案:

答案 0 :(得分:0)

您可以通过隐藏的输入发送它:

@using (Html.BeginForm("Browse", "Home", FormMethod.Get))
{
    @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
    @Html.Hidden("Category",ViewBag.CategoryId)
    <input type="submit" value="Search" />
}