sti*_*bay 11 c# asp.net-mvc razor
我在_Layout页面上有一个简单的搜索表单.
如何轻松地将search-fld中的值传递给控制器?无需创建Model或ViewModel.
@using (Html.BeginForm("Search", "Home", new { id = "search-fld" }, FormMethod.Post, new { @class = "header-search pull-right" }))
{
@Html.AntiForgeryToken()
<input type="text" placeholder="Search" id="search-fld">
<button type="submit">
<i class="fa fa-search"></i>
</button>
}
Run Code Online (Sandbox Code Playgroud)
如果我运行这个,那么"search-fld"会被发送到控制器(offcourse)
使用Ajax表单并使用Jquery获取值?
mat*_*mmo 14
只需提供input一个name属性:
<input type="text" placeholder="Search" id="search-fld" name="searchValue">
Run Code Online (Sandbox Code Playgroud)
然后将该名称与控制器HttpPost方法中的参数进行匹配:
[HttpPost]
public ActionResult Search(string searchValue)
Run Code Online (Sandbox Code Playgroud)