PDA

Click to See Complete Forum and Search --> : VS 2010 passing back ViewData


Bill Crawley
Jul 29th, 2011, 06:01 AM
Hi All,

In one of my actions I set a hidden view data Object:

Setting in the Controller:

IEnumerable<ComputerBreakdownRiskViewModel.CoverType> coverFlatData = _gridService.PopChildGrid(RiskID, PolicyZoneID, SectionID);
ViewData["GridValues"] = coverFlatData;....

declaration in the view:
@Html.Hidden("GridValues", ViewData["GridValues"])

On a call from my view back to my controller I attempt to pass the viewdata Value:

......Update("_SaveAjaxEditing", "ComputerBreakdownRisk", new { ViewData["GridValues"], Model.Covers });

Back in my controller action I make the signature:
public ActionResult _SaveAjaxEditing(int Id, IEnumerable<ComputerBreakdownRiskViewModel.CoverType> GridValues, ComputerBreakdownRiskViewModel.CoverType cover)
{....

I declare it as IEnumerable since this was the type that I set the ViewData up with, however i Receive the following error:

Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.

Serge
Jul 29th, 2011, 10:52 AM
First thing first, you cannot store your IEnumerable values in the hidden box.

Question, are you trying to do the update call through Ajax? If that's the case you will have to store your IEnumerable values as a javascript array. If you are NOT using AJAX, your ViewData will be empty by the time it comes back to your Action.


I think it will be easier for us to understand and give you a proper advice if you can explain what you are trying to accomplish.