In order for these views to be updated with a single controller action method, data sets need to be share a same parent object. A controller action would in-turn resembles this.
public ActionResult GetDataXXX() { var oActionResultData = new CMS() { VegieView = GetVegieViewData(params1), ProteinView = GetProteinViewData(params2), ItemView = GetItemViewData(param3) }; }
Now, views do not need a model declaration. Instead, declare a variable that can hold a data set that can be used in a view like the below in each view.
@{ var result = Model.VegieView as IEnumerable; } @{ var result = Model.ProteinViewas IEnumerable ; } @{ var result = Model.ItemViewas IEnumerable ; }
You can then iterate through data (set) packages to display contents in each view.
For example, for the VegieView, you can do ....
@{ var oVegies = Model.Vegies as IEnumerable<Core.AppView.MVC.SearchServiceReference.VegiePackage>; } @foreach (var x in oVegies ) { foreach (var y in x.Vegies) { <div>@Html.DisplayFor(j=> y.Name)<div> } }
Repeat this with the rest of the partial views, you got yourself a MVC page that calls a single controller action that can update multiple views.
:-) neat!
No comments:
Post a Comment