我有以下看法:
<h2>enter the student name to search</h2>
@using (Html.BeginForm())
{
<label>Search:</label>
<input type="text" name="searchString" />
<input type="submit" name="submit" />
}
并且视图对应于以下控制器
namespace Searching.Controllers
{
public class SearchController : Controller
//somecode
[HttpPost]
public ActionResult SearchIndex(FormCollection formCollection)
{
string searchString=formCollection["searchString"];
var search = from m in db.Searches select m;
if (!String.IsNullOrEmpty(searchString))
{
search = search.Where(s => s.Name.Contains(searchString));
}
return View(search);
}
}
}
控制器名称是 SearchController.cs,传递表单的方法名称是 SearchIndex。Html.BeginForm() 中的参数应该是什么。我是初学者。