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

后端 未结 12 1914
轻奢々
轻奢々 2021-02-04 07:40

So I totally buy into the basic tenents of ASP.NET, testability, SoC, HTML control...it\'s awesome. However being new to it I have a huge hang up with the markup. I know it co

12条回答
  •  失恋的感觉
    2021-02-04 07:57

    use server side comments <%-- comment --%> to separate blocks and increase readability. use extra line spacing to separate blocks too (SO seems to be killing off my line spacing here for some reason).

            <%-- Go through each testimonial --%>
            <% foreach (var testimonial in ViewData.Model.Testimonials) { %>
    
            
    <%= testimonial.summaryText %>
    <%-- Show video if available --%> <% if (string.IsNullOrEmpty(testimonial.Video.FullURL) == false) { %>
    <% Html.RenderAction("YouTubeControl", "Application", new { youTubeId = testimonial.Video.FullURL }); %>
    <% } %>
    <%= testimonial.TestimonialText %>
    <%= testimonial.name %>
    <% } %>

提交回复
热议问题