How to pass ViewData with RenderPartial

Last post 09-12-2008 4:32 AM by illcommunication. 6 replies.

Sort Posts:

  • How to pass ViewData with RenderPartial

    09-08-2008, 9:25 AM

     Hello

     I have a problem with a ascx view control and the view data. If work like this:

     public void AjaxTr<T>(string id, Expression<Action<T>> detailAction,
                Expression<Action<T>> editAction) where T : Controller, new()
            {
                string viewName = ActionUtils.GetViewName<T>(detailAction);
                htmlHelper.RenderPartial(viewName);
            }

    There is no more ViewData in the PartialView (ascx-File). The ViewData in the Controller T(detailAction) is existent and correct. But it is empty in the PartialView (there is only the ViewData of the aspx Page where I call the renderPartial Method).

    Can you help me with this?

  • Re: How to pass ViewData with RenderPartial

    09-11-2008, 7:13 AM
    • Contributor
      4,372 point Contributor
    • tgmdbm
    • Member since 12-17-2007, 2:08 PM
    • Posts 883
    • ASPInsiders
      TrustedFriends-MVPs

     make sure the ascx file inherits from ViewUserControl.

  • Re: How to pass ViewData with RenderPartial

    09-11-2008, 8:13 AM

     Hello

    Ok, maybe I was not precise enough.

    I want to dynamically render an action via renderpartial. But renderpartial does not support to render actions as I understand.

    I have this function:

    public void AjaxDiv<T>(string id, string title, Expression<Action<T>> detailAction,
                Expression<Action<T>> editAction, bool isOpen) where T : Controller, new()
            {

    And from the Action<T> editAction I want to get the viewdata or better, I want to call the editAction like when I am just opening it directly via link.

    And this function is in a separated class library.

    In the view it is like this:

    <% AjaxBlocks.AjaxDiv<SupplierProductDataController>("supplierData", "Supplier data",
            c => c.List(product.Id), false); %>

    The target is, that the first time I load the view/controller it renders everything. And then I have an AJAX div which updated via JQuery. Everything with the JQuery works perfect. It is just a problem to load the usercontrol with the first page request directly (via ajax the page load is not that smooth cause every block appears another time).

    One problem is, that I want to render this partial view but it is from another controller. With this renderview I can only render partialviews (ascx) from shared folders or from the correct controller which contains the main view. Maybe the old renderaction would have solved my problem.

  • Re: How to pass ViewData with RenderPartial

    09-11-2008, 9:32 PM
    Answer
    • Contributor
      4,372 point Contributor
    • tgmdbm
    • Member since 12-17-2007, 2:08 PM
    • Posts 883
    • ASPInsiders
      TrustedFriends-MVPs

    illcommunication:
    I want to call the editAction like when I am just opening it directly via link.

    You want RenderAction, not RenderPartial

  • Re: How to pass ViewData with RenderPartial

    09-12-2008, 12:50 AM

     Yes, but there is not more renderaction in Preview 5. What is the solution?

  • Re: How to pass ViewData with RenderPartial

    09-12-2008, 1:00 AM
    • Contributor
      4,372 point Contributor
    • tgmdbm
    • Member since 12-17-2007, 2:08 PM
    • Posts 883
    • ASPInsiders
      TrustedFriends-MVPs

    What are you talking about? Of course there is!

    Look in Microsoft.Web.Mvc.dll?

  • Re: How to pass ViewData with RenderPartial

    09-12-2008, 4:32 AM

     Ok, it works like that. Thank you very much and sorry for the "blindness" (only used the system.web.mvc and visual studio did not recommend any using when I right clicked my mouse).

    Now the first request is rendered directly with renderaction and then the block can be edited via ajax.

Page 1 of 1 (7 items)