I'm wondering how to best tackle this, since what I have now works great for a hard-coded column in my view -- I'm wondering how I can extend it to allow the column to be dynamic.
CONTROLLER:
var dc = new DataContextDC();
return View(dc.items.Where(i=>i.IsPublic == true));
VIEW:
<% foreach (var grp in Model.GroupBy(s => s.GroupColumn)) { %>
<%= Html.Encode(grp.Key) %>
<% foreach (var item in grp) { %>
<%= Html.Encode(item.Title) %>
<% } %>
<% } %>
As stated, the objective is to let the user choose which column replaces "GroupColumn" above. I'd like to avoid adding any external libraries, etc.
I see using reflection (slow, but fully dynamic) or since this is one View in my application, I just duplicate the above code for each column in the database and then put a switch statement on it (quick, and dirty, but effective)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…