我有一个局部 View ,它是一个搜索文本框和按钮。
我正在尝试将其设为局部 View ,以便我可以在多个位置渲染它。当用户点击搜索时,我希望它重定向到/Home/Search,它将根据搜索框中的内容显示项目列表。
这是正确的方法还是我应该让表单只运行/Home/Search Index() 操作而根本没有部分 View Controller ?
局部 View
<% using (Html.BeginForm("Search", "SearchBox")) {%>
<%: Html.TextBoxFor(model => model.searchTerm) %>
<input type="submit" value="Search" />
<% } %>
局部 View Controller
public class SearchBoxController : Controller
{
public ActionResult Search(ViewModels.SearchViewModel item)
{
Models.DataClasses1DataContext db = new Models.DataClasses1DataContext();
List<Models.Item> retVal = (from p in db.Items
where p.Name.Contains(item.searchTerm)
select p).ToList();
return RedirectToAction("Search", "Home"); //No data... What to do????
}
}
最佳答案
or should I make the form just run the /Home/Search Index() action and not have a partial view controller at all?
绝对是的。就是这样,没有真正需要部分 Controller ,特别是如果它涉及额外的重定向。
关于c# - MVC2 局部 View 、搜索控件 - 设计/实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3763036/