I am learning MVC and am confused by this. I am trying to use some common code that receives data and displays it in a WebGrid on a partial view that I can use on multiple pages.
My home controller The index method simply returns the view (). The Home view is as follows:
@using (Ajax.BeginForm("SearchAction", "Search",
new AjaxOptions { UpdateTargetId = "data-grid", HttpMethod = "Post" }))
{
@Html.TextBoxFor(model => model.name)
<input type="submit" value="Search" />
}
@{
<div id="data-grid">
@Html.Partial("SearchResults", Model)
</div>
}
I am trying to use Ajax so as not to lose the search form data when I click on a link to a WebGrid pager that displays as regular links.
My SearchController is as follows:
public ActionResult SearchAction(string name)
{
return RedirectToAction("SearchResults", new { name = name });
}
public ActionResult SearchResults(string name)
{
VieweBag.Members = MyQueryResults;
return PartialView();
}
My sharing view is SearchResults, data is passed through ViewBag.Members:
@{
var grid = new WebGrid(null, rowsPerPage: ViewBag.Pagesize);
grid.Bind(ViewBag.Members);
@grid.GetHtml(
}
, , , ViewBag.Pagesize ViewBag.Members , . , ViewBag, . ?
, ( ), , , , view . , , .
/ , , - :\