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

Asp.net mvc MVC4:如何将表单参数从视图发送到控制器?,asp.net-mvc,asp.net-mvc-3,asp.net-mvc-4,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, C

浏览操作:

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>

@使用(Html.BeginForm(“浏览”、“主页”、FormMethod.Get))
{
@TextBox(“SearchString”,ViewBag.CurrentFilter为字符串)
}

您可以在隐藏输入中发送:

@using (Html.BeginForm("Browse", "Home", FormMethod.Get))
{
    @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
    @Html.Hidden("Category",ViewBag.CategoryId)
    <input type="submit" value="Search" />
}
@使用(Html.BeginForm(“浏览”、“主页”、FormMethod.Get))
{
@TextBox(“SearchString”,ViewBag.CurrentFilter为字符串)
@Html.Hidden(“Category”,ViewBag.CategoryId)
}

而不是这一行:@Html.Hidden(“Category”,ViewBag.CategoryId)我使用了以下代码:int CategoryId=ViewBag.CategoryId@Html.Hidden(“Category”,CategoryId);因为它对dynamic ViewBag.CategoryId有错误。也可以选择强制转换ViewBag结果
@Html.Hidden(“Category”,(int?)ViewBag.CategoryId)
以跳过执行
int CategoryId=ViewBag.CategoryId