During Rendering Each poular list use javascript to send (jquery) ajax request and fill it.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Yes, I did that, thanks.... It was a little more complicated though as I couldn't get a $.post(....) working for each item? I had to get it at the end and .append new data dynamically to each rows dynamic id.
Here is some code of what I did if it will help someone.
In SearchContoller.cs I added.
public class JsonRSVP
{
public int RsvpID { get; set; }
public int DinnerID { get; set; }
public string AttendeeName { get; set; }
public string AttendeeNameId { get; set; }
}
[HttpPost]
public ActionResult GetRSVPListByDinnerId(int dinnerId)
{
var RSVPs = dinnerRepository.FindRsvpsByDinnerId(dinnerId);
var RSVPList = from rsvp in RSVPs
orderby rsvp.AttendeeNameId ascending
select rsvp;
var jsonRSVPS = RSVPs.AsEnumerable().Select(item => JsonRSVPFromRSVP(item));
return Json(jsonRSVPS.ToList());
}
private JsonRSVP JsonRSVPFromRSVP(RSVP rsvp)
{
return new JsonRSVP
{
RsvpID = rsvp.RsvpID,
DinnerID = rsvp.DinnerID,
AttendeeName = rsvp.AttendeeName,
AttendeeNameId = rsvp.AttendeeNameId
};
}
In the nerddinner.js file I added a line
NerdDinner._renderDinners = function (dinners) {
...
...
//requests GetRSVPListNames method in SearchController and returns json object to pass to NerdDinner._RSVPList for processing
$.post("/Search/GetRSVPListByDinnerId", { "dinnerId": dinner.DinnerID }, NerdDinner._RSVPList, "json");
});
and a new function to take care of the returned json object
davidtran
Member
38 Points
34 Posts
NerdDinner, simple view extension?
Aug 06, 2010 02:24 PM|LINK
Does anyone have a code example of how to extend the view of the Dinners Index page to also display the RSVP's in the list of the POPULAR DINNERS?
So for example the Dinners list will read on the home page of nerddinners. (RSVP names from the RSVP table, underlined, bold, italic)
Popular Dinners
dorkfest lansing 2010
Dec 31 with 108 RSVPs (James Dean, Fraggle Rock, Homer Simpson, Cartman etc...)
2010 Opening Ceremony
Dec 2 with 38 RSVPs (Miss Piggy, Stan, Marge Simpson, Lisa Simpson, Johnny Cash etc...)
WarpSpeedDating @ Science Museum, London
Oct 20 with 15 RSVPs (John Wayne, Bill & Ted, Jet li, Jackie Chan)
Many thanks for any help
David
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: NerdDinner, simple view extension?
Aug 10, 2010 02:49 AM|LINK
Quick solution, use Ajax to fill each Rsvp's
During Rendering Each poular list use javascript to send (jquery) ajax request and fill it.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
davidtran
Member
38 Points
34 Posts
Re: NerdDinner, simple view extension?
Aug 10, 2010 06:05 AM|LINK
Yes, I did that, thanks.... It was a little more complicated though as I couldn't get a $.post(....) working for each item? I had to get it at the end and .append new data dynamically to each rows dynamic id.
Here is some code of what I did if it will help someone.
In SearchContoller.cs I added.
public class JsonRSVP { public int RsvpID { get; set; } public int DinnerID { get; set; } public string AttendeeName { get; set; } public string AttendeeNameId { get; set; } } [HttpPost] public ActionResult GetRSVPListByDinnerId(int dinnerId) { var RSVPs = dinnerRepository.FindRsvpsByDinnerId(dinnerId); var RSVPList = from rsvp in RSVPs orderby rsvp.AttendeeNameId ascending select rsvp; var jsonRSVPS = RSVPs.AsEnumerable().Select(item => JsonRSVPFromRSVP(item)); return Json(jsonRSVPS.ToList()); } private JsonRSVP JsonRSVPFromRSVP(RSVP rsvp) { return new JsonRSVP { RsvpID = rsvp.RsvpID, DinnerID = rsvp.DinnerID, AttendeeName = rsvp.AttendeeName, AttendeeNameId = rsvp.AttendeeNameId }; }In the nerddinner.js file I added a line
NerdDinner._renderDinners = function (dinners) { ... ... //requests GetRSVPListNames method in SearchController and returns json object to pass to NerdDinner._RSVPList for processing $.post("/Search/GetRSVPListByDinnerId", { "dinnerId": dinner.DinnerID }, NerdDinner._RSVPList, "json"); });and a new function to take care of the returned json object
NerdDinner._RSVPList = function (RSVPs) { //$('#dinnerList').append("DinnerId: " + RSVP.DinnerID[0]); //jQuery.each( collection, callback(indexInArray, valueOfElement) ) $.each(RSVPs, function (i, rsvp) { $('#dinnerID' + rsvp.DinnerID).append(rsvp.AttendeeNameId); }); }In the IDinnerRepository.cs
IQueryable<RSVP> FindRsvpsByDinnerId(int dinnerId); IQueryable<RSVP> FindAllRSVPs();and in DinnerRepository.cs
public IQueryable<RSVP> FindAllRSVPs() { return db.RSVPs; } public Dinner GetDinner(int id) { return db.Dinners.SingleOrDefault(d => d.DinnerID == id); }A little long winded I know! lol
Is there a more robust way to do this? I think I saw something in the MvcMusicStore in the admin section? Can anyone give me any hints?
I will take apart the MvcMusicStore code now :D
Thanks
David