我目前正在编写一个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