views:

58

answers:

3

I think this may be a very simple question, but I am only just starting out with .net and c# at all, and only really just finally getting my head around OO stuff.

I have built the NerdDinner application, and I am building on top of it currently with my own project.

What I need to do, in the context of nerd dinner, is display the details of a dinner, but also show all the assoicated RSVP's on the same page.

The url could be the same as normal

dinners/details/2

but the 2 would be used to bring back all rsvp's related to that, and display them in a list on the same page.

I have spend some time trying to do this in the dinnerRepository.cs file, but I'm getting a bit stuck, and not sure the best way to do this.

I would then like to be able to add more rsvp's from that same page (I understand that dosent work in this example, but you seen that I am trying to Add more of rows to tableB, related to a single row in tableA)

Please only answer the first question if you feel the second part should be asked elsewhere.

Thanks so much for any help.

A: 

IIRC, the details view is passed an instance of Dinner. Simply render out the RSVPs for that dinner on the details page.

JeffreyABecker
So are you saying I don't have to do anything to the model, it should already be there?
optician
A: 

I like using RenderAction for this kind of thing. RenderAction allows you to target a specific subcontroller method to render a subview in the page. Since it is a modular technique, it can be used in more than one page without changes.

RenderAction is part of the Futures assembly: Microsoft.Web.Mvc.

Robert Harvey
+1  A: 

You do not need to change the dinnerRepository.cs file at all. The dinner model already has a RSVP collection. You will just need to modify the Details view as such:

    <p>
    <% foreach(NerdDinner.Models.RSVP rsvp in this.Model.RSVPs)
       { %>
       <%= Html.Encode(rsvp.AttendeeName) %>
       <br />
       <%} %>
    </p>

Your done.

KP
Thanks for making it so clear as well, perfect!
optician