Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC > ASP.NET WebForms, Why?
    text
    copied!<p>I've now completed my first web application using ASP.NET MVC and overall, I still am not grasping why this is getting all the praise and glory. Maybe I'm being stubborn. I know that what makes MVC great is that is forces separation between the presentation layer and the business object or data layer along with its stateless operation. I also know that when you are working with the view, it appears that the code is less readable (see my example below).</p> <p>So I guess my question is... If the separation is the concern, why not just separate.</p> <p><strong>Web Forms View Code:</strong></p> <pre><code>//UI &lt;h2&gt;&lt;asp:Label ID="lblPageHeader" runat="server" /&gt;&lt;/h2&gt; </code></pre> <p><strong>Web Forms Code Behind:</strong></p> <pre><code>//CODE BEHIND this.lblPageHeader.Text = myObject.Header; </code></pre> <p><strong>MVC Code View:</strong></p> <pre><code>//UI &lt;h2&gt;&lt;%= Html.Encode(Model.PageTitle) %&gt;&lt;/h2&gt; </code></pre> <p><strong>MVC Controller Code:</strong></p> <pre><code>index = new Index { PageText = sb.ToString(), PageTitle = "WELCOME" }; return View(index); </code></pre> <p>Again, I might be being stubborn, but one of the things that I really liked in WebForms is the ease in setting object properties like DataSources and Text values. It seems like this is completely different in MVC and less readable which makes me wonder about long term maintenance.</p> <p><strong>EDIT</strong> After looking into the typed models, I think the readability of the code is substantially improved.</p>
 

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