Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While I fully agree that that is ugly markup, I think using the ugly view syntax to write off ASP.NET MVC as a whole is not fair. The view syntax has gotten the least attention from Microsoft, and I am fully expecting something to be done about it soon. </p> <p>Other answers have discussed the benefits of MVC as a whole, so I will focus on the view syntax:</p> <p>The encouragement to use Html.ActionLink and other methods that generate HTML is a step in the wrong direction. This smacks of server controls, and, to me, is solving a problem that doesn't exist. If we are going to generate tags from code, then why bother using HTML at all? We can just use DOM or some other model and build up our content in the controller. Ok, that sounds bad, doesn't it? Oh yes, separation of concerns, that is why we have a view. </p> <p>I think the correct direction is to make the view syntax as much like HTML as possible. Remember, a well designed MVC should not only give you separation of code from content, it should let you streamline your production by having people who are expert in layout work on the views (even though they do not know ASP.NET), and then later as a developer you can step in and make the view mockup actually dynamic. This can only be done if if the view syntax looks very much like HTML, so that the layout folks can use DreamWeaver or whatever the current popular layout tool is. You might be building dozens of sites at once, and need to scale in this way for efficiency of production. Let me give an example of how I could see the view "language" working:</p> <pre><code>&lt;span mvc:if="ViewData.Model.ShowPrevious" style="float: left;"&gt; &lt;a mvc:inner="ViewData.Model.PreviousPost.Subject" href="view/{ViewData.Model.PreviousPost.Id}"&gt;sample previous subject&lt;/a&gt; &lt;/span&gt; &lt;span mvc:if="ViewData.Model.ShowNext" style="float: left;"&gt; &lt;a mvc:inner="ViewData.Model.NextPost.Subject" href="view/{ViewData.Model.NextPost.Id}"&gt;sample next subject&lt;/a&gt; &lt;/span&gt; &lt;div mvc:if="ViewData.Model.ShowNextOrPrevious" style="clear: both;" /&gt; </code></pre> <p>This has several advantages:</p> <ul> <li>looks better</li> <li>more concise</li> <li>no funky context switching betwen HTML and &lt;% %> tags</li> <li>easy to understand keywords that are self-explanatory (even a non-programmer could do this - good for parallelization)</li> <li>as much logic moved back into controller (or model) as possible</li> <li>no generated HTML - again, this makes it very easy for someone to come in and know where to style something, without having to mess around with Html. methods</li> <li>the code has sample text in it that renders when you load the view as plain HTML in a browser (again, good for layout people)</li> </ul> <p>So, what exactly does this syntax do?</p> <p>mvc:inner="" - whatever is in the quotes gets evaluated and the inner HTML of the tag gets replaced with the resulting string. (Our sample text gets replaced)</p> <p>mvc:outer="" - whatever is in the quotes gets evaluated and the outer HTML of the tag gets replaced with the resulting string. (Again, sample text gets replaced.)</p> <p>{} - this is used for inserting output inside of attributes, similar to &lt;%= %></p> <p>mvc:if="" - insde the qoutes is the boolean expression to be evaulated. The close of the if is where the HTML tag gets closed.</p> <p>mvc:else</p> <p>mcv:elseif="" - ...</p> <p>mvc:foreach</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload