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 Layout.cshtml上的ASP.NET MVC搜索框_Asp.net Mvc - Fatal编程技术网

Asp.net mvc Layout.cshtml上的ASP.NET MVC搜索框

Asp.net mvc Layout.cshtml上的ASP.NET MVC搜索框,asp.net-mvc,Asp.net Mvc,我已经创建了搜索表单和结果,从中使用PagedList Nuget包处理分页和排序 不过,我需要的帮助是,如何将搜索表单放在母版页上?(_layout.cshtml)?放置一个from,其中包含一个文本框和一个按钮,表单的操作将是搜索操作 \u layout.cshtml页面中的Ex代码 @using(Html.BeginForm("ActionName","ControllerName", FormMethod.Get)) { @Html.TextBoxFor(m => m.Qu

我已经创建了搜索表单和结果,从中使用PagedList Nuget包处理分页和排序


不过,我需要的帮助是,如何将搜索表单放在母版页上?(_layout.cshtml)?

放置一个from,其中包含一个文本框和一个按钮,表单的操作将是搜索操作

\u layout.cshtml
页面中的Ex代码

@using(Html.BeginForm("ActionName","ControllerName", FormMethod.Get))
{
    @Html.TextBoxFor(m => m.Query)

    <div>
        <input type="submit" value="Search" />
    </div>
}
@使用(Html.BeginForm(“ActionName”、“ControllerName”、FormMethod.Get))
{
@Html.TextBoxFor(m=>m.Query)
}

谢谢你的帮助,让它正常工作,但必须更改FormMethod。请访问FormMethod.Post。另外,在显示结果时,如何清除文本框中的条目?您应该使用
GET
,因为这意味着服务器的请求不会更改任何数据,但是
POST
会更改关于清除字段的内容,在表单的POST操作中,使传递给视图的查询属性等于空字符串,但如果使用GET,则不会返回任何搜索结果。。。我修正了这一点,因为代码专门查找GET并将搜索设置为nothing。再次感谢。为您发布的控制器操作、模型和视图表单发布示例代码,但我可以说
Http
动词(
GET
post
)与数据和应用程序逻辑无关