【发布时间】:2015-02-07 18:25:36
【问题描述】:
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(FormCollection fc)
{
String sc = fc["SearchString"];
return RedirectToAction("SearchFromObject", new { id = sc });
}
public ActionResult SearchFromObject(string searchString)
{
var Items = from m in db.Objects
select m;
if (!String.IsNullOrEmpty(searchString))
{
Items = Items.Where(s => s.Name.Contains(searchString));
}
return View(Items);
}
此代码返回字符串 sc 的空值。为什么??在我看来,有一个文本框。我想在单击按钮并检索与搜索关键字相关的数据时将该值作为参数传递给 SearchFromObject 方法。这是我的观点
@{
ViewBag.Title = "Search";
}
<h2>Search</h2>
<p>
@using (Html.BeginForm())
{<p>
Title: @Html.TextBox("SearchString") <br />
<input type ="submit" value="Search" />
</p>
}
【问题讨论】:
-
你能显示你的视图的渲染 html 吗?现在对我来说还可以。
标签: c# asp.net-mvc formcollection