insert PartialView w/ data from aspx page

Last post 07-03-2009 10:00 AM by currentspulledmeunder. 2 replies.

Sort Posts:

  • insert PartialView w/ data from aspx page

    07-02-2009, 6:13 AM

    I hope this will be an easy answer but I can't seem to find it searching.

    I have an aspx page with a partial view inside of it. 

    I am inserting the partial view with the syntax like this:  <TagPrefix:TagName ID="PartialView1" runat="server"/>

    I get "Object not set to reference errors though, unless I click a link to the data with my controller like this:

    The partial view has a controller that loads data like this:

    public ActionResult MyPartialViewWithData()
            {
                return PartialView("Data/Home/Home", _entities.MyDataSet.ToList());
            }

    Is there a way to insert the PartialView with a reference to the model? I found html.RenderPartial and some others but had trouble getting it to work.

    Thanks in advance!


  • Re: insert PartialView w/ data from aspx page

    07-02-2009, 9:55 AM
    Answer
    • Member
      40 point Member
    • LandVP
    • Member since 07-02-2009, 8:27 AM
    • Ukraine
    • Posts 5

    You have to use html.RenderPartial to render your partial view on the page

    <% Html.RenderPartial("YourViewName", YourModel); %>


    And I think that you have to use an action from your main view (that contains your partial view). I.e. do not create the action for your partial view. Instead of it you have to use your main view controller action.

    Vladimir
  • Re: insert PartialView w/ data from aspx page

    07-03-2009, 10:00 AM

    I've been using entities to get data from my database.  Do you know how I can convert them into Models so that I can use the RenderPartial syntax? 



Page 1 of 1 (3 items)