Would you use this ASP.NET MVC view syntax?

I have suggested what I think is the best syntax for ASP.NET MVC views in this question . Since this question has been answered, I think my answer will generate a little feedback, so I am posting it as my own question here.

+1


source to share


6 answers


You're on the right track, but I think you've gone too far. Balance mixes the code with the html where it flows rather than over complicating it and also doesn't create a soup tag. The best viewer I've found that does this is Spark .



Take a look at it and you will find what you are suggesting in a more subtle and readable way.

0


source


You are using markup to represent your code. My opinion is this: where code is needed, just use code that is always more flexible. If markup is required, use markup. This article explains exactly my point. Sometimes the line between code and markup is blurry.



+2


source


I am very sorry that people will stop considering XML as a programming language.

+1


source


Perhaps you should use this one instead of the MVC syntax called HAML.

%h2= Model.CategoryName
%ul
  - foreach (var product in Model.Products)
    %li
      = product.ProductName 
      .editlink
        = Html.ActionLink("Edit", new { Action="Edit", ID=product.ProductID })
= Html.ActionLink("Add New Product", new { Action="New" })

      

replaces

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" 
    CodeBehind="List.aspx" Inherits="MvcApplication5.Views.Products.List" Title="Products" %>
<asp:Content ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
 <h2><%= ViewData.Model.CategoryName %></h2>
  <ul>
    <% foreach (var product in ViewData.Model.Products) { %>
      <li>
        <%= product.ProductName %> 
        <div class="editlink">
          (<%= Html.ActionLink("Edit", new { Action="Edit", ID=product.ProductID })%>)
        </div>
      </li>
    <% } %>
  </ul>
  <%= Html.ActionLink("Add New Product", new { Action="New" }) %>
</asp:Content>

      

+1


source


Also take a look at the JSPs: they needed to introduce an "expression language" to get some code power in the jsp markup. The result is very inconvenient IMHO. It even requires an explicit mapping (in XML, of course) to access a simple function from that expression language.

See this .

0


source


In addition to maucsch and frosted dots, doesn't that mean the server will have to load and parse the entire page looking for "mvc:"? And isn't that one reason not to use web forms?

-2


source







All Articles