[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