code_junkie

How do I get over my fears of <% %> in my ASP.Net MVC markup?

Nov 12th, 2011
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. public static string RSSRepeater<T>(this HtmlHelper html, IEnumerable<T> rss) where T : IRSSable
  2. {
  3. StringBuilder result = new StringBuilder();
  4.  
  5. if (rss.Count() > 0)
  6. {
  7. foreach (IRSSable item in rss)
  8. {
  9. result.Append("<item>").Append(item.GetRSSItem().InnerXml).Append("</item>");
  10. }
  11. }
  12.  
  13. return result.ToString();
  14. }
  15.  
  16. <%-- Go through each testimonial --%>
  17. <% foreach (var testimonial in ViewData.Model.Testimonials) { %>
  18.  
  19. <div class="testimonialFrame">
  20. <div class="testimonialHeader"><%= testimonial.summaryText %></div>
  21.  
  22.  
  23. <%-- Show video if available --%>
  24. <% if (string.IsNullOrEmpty(testimonial.Video.FullURL) == false) { %>
  25.  
  26. <div style="padding-top:12px">
  27. <% Html.RenderAction("YouTubeControl", "Application", new { youTubeId = testimonial.Video.FullURL }); %>
  28. </div>
  29.  
  30. <% } %>
  31.  
  32. <div class="roundedBox" style="margin-top:15px">
  33. <div id="txtTestimonialText" class="testimonialText paddedBox"><%= testimonial.TestimonialText %></div>
  34. </div>
  35.  
  36. <div class="testimonialFooter"><%= testimonial.name %></div>
  37. </div>
  38.  
  39. <% } %>
  40.  
  41. <%-- render section --%>
  42. <% RenderTextSection(section); %>
  43.  
  44. htmlControl.RenderControl(new HtmlTextWriter(Response.Output));
  45.  
  46. protected void RenderTextSection(ProductSectionInfo item)
  47.  
  48. {
  49. HtmlGenericControl sectionTextDiv = new HtmlGenericControl("div");
  50.  
  51. bool previousHasBulletPoint = false;
  52. System.Web.UI.HtmlControls.HtmlControl currentContainer = sectionTextDiv;
  53.  
  54. foreach (var txt in item.DescriptionItems)
  55. {
  56. if (!previousHasBulletPoint && txt.bp)
  57. {
  58. // start bulleted section
  59. currentContainer = new HtmlGenericControl("UL");
  60. sectionTextDiv.Controls.Add(currentContainer);
  61. }
  62. else if (previousHasBulletPoint && !txt.bp)
  63. {
  64. // exit bulleted section
  65. currentContainer = sectionTextDiv;
  66. }
  67.  
  68. if (txt.bp)
  69. {
  70. currentContainer.Controls.Add(new HtmlGenericControl("LI")
  71. {
  72. InnerHtml = txt.t
  73. });
  74. }
  75. else
  76. {
  77. currentContainer.Controls.Add(new HtmlGenericControl()
  78. {
  79. InnerHtml = txt.t
  80. });
  81. }
  82.  
  83. previousHasBulletPoint = txt.bp;
  84. }
  85.  
  86. sectionTextDiv.RenderControl(new HtmlTextWriter(Response.Output));
  87. }
Add Comment
Please, Sign In to add comment