Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark Evans 86 posts 116 karma points
    Sep 12, 2014 @ 12:09
    Mark Evans
    0

    passing data between partial views

    how can i pass additional info in a call to a partial view?

    im trying

    from partial view A

    Html.RenderPartial(partialviewB, widget, new ViewDataDictionary(this.ViewData) { { "NewRow", true } });

    but nothing is in the ViewData when i try and access it this way in the called partial view (so a is always false)

    in partial view B

    var a = Convert.ToBoolean(ViewData["NewRow"]);

     

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    Sep 12, 2014 @ 12:43
    Alex Skrypnyk
    100

    Hi Mark,

    ViewDataDictionary can be used to replace the ViewData dictionary in the partial view... If you don't pass a ViewDataDictionary parameter then the parial's viewdata is the same as the parents.

    @Html.Partial("_SomeTable", (List<CustomTable>)ViewBag.Table, new ViewDataDictionary {{ "Key", obj }});
    

    http://www.codenoevil.com/pass-additional-viewdata-asp-net-mvc-4/

  • Mark Evans 86 posts 116 karma points
    Sep 12, 2014 @ 15:16
    Mark Evans
    0

    ok so is this the best approach for passing extra data to my partial view?

     

    if so, how can i get it to work, the viewdata is empty in my called partial view when i try to access the key....

Please Sign in or register to post replies

Write your reply to:

Draft