Results 1 to 2 of 2

Thread: passing back ViewData

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    passing back ViewData

    Hi All,

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

    Setting in the Controller:

    Code:
    IEnumerable<ComputerBreakdownRiskViewModel.CoverType> coverFlatData = _gridService.PopChildGrid(RiskID, PolicyZoneID, SectionID);
                ViewData["GridValues"] = coverFlatData;....
    declaration in the view:
    Code:
    @Html.Hidden("GridValues", ViewData["GridValues"])
    On a call from my view back to my controller I attempt to pass the viewdata Value:

    Code:
    ......Update("_SaveAjaxEditing", "ComputerBreakdownRisk", new { ViewData["GridValues"], Model.Covers });
    Back in my controller action I make the signature:
    Code:
    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.

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Re: passing back ViewData

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width