[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);
}
此代码为String sc返回空值。为什么??在我看来,有一个文本box.i希望该值传递给SearchFromObject方法作为参数点击按钮和检索到搜索keyword..Here是我的看法FormCollection在mvc中返回空值
@{
ViewBag.Title = "Search";
}
<h2>Search</h2>
<p>
@using (Html.BeginForm())
{<p>
Title: @Html.TextBox("SearchString") <br />
<input type ="submit" value="Search" />
</p>
}
您能不能告诉你呈现的查看HTML?现在看起来好了。 – 2015-02-07 18:52:47