从不同的视图发布表单时我遇到了问题...我使用相同的表单,它将在一个视图中工作,但不会在另一个视图中工作。在帖子中出现错误时,参数将作为null传递。这是我的形式:asp.net mvc张贴强类型传递null?
<% using (Html.BeginForm()) { %>
<table>
<tr>
<td colspan="4" style="line-height:20px;"><label for="Search.searchString">Search</label></td>
</tr>
<tr>
<td><%= Html.TextBox("Search.searchString") %>
</td>
<td><label for="Search.category"><nobr>In Category</nobr></label></td>
<td><%= Html.TextBox("Search.category") %></td>
<td><input type="submit" value="Search" /></td>
</tr>
</table>
<% } %>
我有2个视图...索引和搜索视图。当我从索引视图发布这个表单时,它工作正常。当我从搜索视图中发布它时,它告诉我,我的搜索对象为空。这是我的帖子方法:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(Search search)
{
if (String.IsNullOrEmpty(search.searchString))
search.searchString = "all";
return RedirectToRoute("search", new RouteValueDictionary { { "search", search.searchString }, { "category", search.category } });
}
的方法,后两种索引和搜索都是一样的,所以我相当困惑,为什么一个作品,而其他没有。有什么想法吗?谢谢您的帮助!
索引和搜索视图都继承了同一个对象。那是你问的吗? – Arthurdent510 2009-12-09 17:45:57