我目前正在編寫一個web應用程序,它需要將一些配置設置從設置頁面傳遞到帶有搜索框的頁面頁面。在MVC中的視圖之間傳遞數據
目前我正在從設置頁面傳遞配置數據到主頁用:
public ActionResult Settings(Configuration configuration)
{
return RedirectToAction("ConfigSet", "Home", configuration);
}
和家庭控制器:
public ActionResult ConfigSet(Configuration configuration)
{
return View("Index");
}
我產生了局部視圖:
public PartialViewResult Search(string q)
{
List<Stuff> results = this.Search(q);
return PartialView("SearchResults", results);
}
隨着渲染像這樣的局部視圖:
@using (Ajax.BeginForm("Search", "Home", new AjaxOptions {
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "searchResults",
}))
{
<input type="text" name="searchString" />
<input type="submit" value="Search" />
}
我的問題是如何將配置設置傳遞給部分視圖?我一直在想這個問題幾天,我對此感到困惑。
謝謝。但是,我不確定如何將設置頁面上設置的配置傳遞給搜索viewresult方法。我可以通過configset方法將數據傳遞給母版頁,但無法使用您的想法將配置傳遞給搜索方法。 – 2012-04-23 13:09:35
在您的ajax.beginform中,您可以從model.configuration呈現所有配置內容;在ajax請求提交哪個將要調用搜索動作,爲此,你將不得不將簽名更改爲'公共PartialViewResult搜索(配置配置)' – 2012-04-23 14:02:24
更新了答案,看看 – 2012-04-23 14:10:25