我在我的控制器文件夹中有一个SearchController.cs,它有一个名为Index的Action。我的搜索文件夹中有一个名为Index 下面的代码是针对我的/控制器/ SearchControllerHtml.BeginForm问题()asp.net MVC 2
private TEAM2BooksDBEntities _db = new TEAM2BooksDBEntities();
[HttpPost]
public ActionResult Index(string SearchFor)
{
var query = _db.Books.Where(em => em.title.Contains(SearchFor)).ToList();
return View(query);
}
下面的代码是在我的/首页/索引
<% using(Html.BeginForm("Index","Search")){ %>
<%= Html.TextBox("SearchFor") %>
<input type="submit" value="Submit" />
<% }%>
但无论我做什么时我点击提交按钮,它只是重新加载当前页面。我希望它将“SearchFor”框的内容作为参数发送到Search控制器中的Index操作。我怎样才能解决这个问题?
如何你的get方法是什么样子?另外你如何区分你的post方法被调用。 – dotnetstep
也许是这个问题,我不认为我有一个get方法。 – Dominic
乍一看,一切似乎都应该如此。我会尝试以下方法:(1)在Home/Index页面上执行View-> Source,并确保'