I\'ve been using ASP.Net WebForms for the last year or two at work for developme
ID: 651896 • Letter: I
Question
I've been using ASP.Net WebForms for the last year or two at work for development, but I've used PHP for personal projects for 10 years. So, I'm far more adept at developing with PHP.
When it comes to ASP.Net MVC, I have no experience with it because I've avoided it because I assumed it would just be a more complicated form of WebForms. Recently, I've been doing more research and it's sounding like MVC might be closer to what what I want. But, something I'm still not clear on is which ASP.Net programming model is closer to developing with PHP.
My biggest complaint about ASP.Net WebForms is the "magic boxes." Namely the View State, and ScriptManager.
I don't like that WebForms messes with my client side HTML/JavaScript/CSS. WebForms does a lot of this including, but not limited to:
Inserting JavaScript that I can't modify and have to rely on Microsoft to ensure cross-browser compatibility.
Forcefully changing the name attributes of tags that make use of runat="server".
Wrapping the contents of a <form> with a <div> tag.
Forcing wrapping everything inside one big <form> tag.
Everything in WebForms feels like it's catered to in-experienced web-developers who only know how to write Windows applications with .Net.
Standard names for tags and attributes are changed when using <asp:xxx> tags. For example, instead of an anchor (<a>) tag, it's a "hyperlink" (i.e. <asp:HyperLink>). Instead of href= it's NavigationUrl=.
The event driven model.
I also don't like the complete separation of server side code from the client side code. I miss being able to do things like this...
<table>
<tr>
<td>Name</td>
<td>Age</td>
</tr>
<? foreach( $people as $person ) { ?>
<tr>
<td><?= $person->name ?></td>
<td><?= $person->age ?></td>
</tr>
<? } ?>
</table>
So, with these points in mind, which programming model is closer to development with PHP (i.e. do the annoyances of WebForms that I've listed here exist in MVC)?
Explanation / Answer
In ASP.NET MVC (3 and greater) using razor the example would be
<table>
<tr>
<td>Name</td>
<td>Age</td>
</tr>
@foreach(var person in people)
{
<tr>
<td>@person.Name</td>
<td>@person.Age</td>
</tr>
}
</table>
The same syntax can be used in ASP.NET Web Pages. There are differences in there two technologies.
In MVC there are separate classes for controllers and models. The project has more specific structure. The project is built before deployment.
Web Pages project is compiled on the fly, so you can just change a file and changes appear. It doesn't have same kind of "pipeline" as MVC.
I would recommend MVC, but Web Pages is more like PHP.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.