Postbacks get their own code.
The hardest thing for me to wrap my head around, and what ended up impressing me the most, was the fact that IsPostback has been banished. Hitting the same block of Page_Load code on both GET and POST is asking for trouble ("Why isn't this value getting captured? ASP.NET is broken!! Oh, never mind, I'm overwriting it in Page_Load. Whoops.") MVC just doesn't go there. Instead, you set up two methods (OK, "Controller Actions"), decorate one with a [HttpGet] attribute, and one with a [HttpPost] attribute, each with one job. Separation of concerns, for a rosy-fresh code smell.These attributes are called Action Filters, and they can do some pretty neat things, such as force login or set up output caching. Action Filters can be applied to the individual Action method, the Controller class (allowing you to limit a controller to signed-in users, or members of certain role), or applied globally. And you can roll your own by subclassing System.Web.Mvc.FilterAttribute.
Controllers handle the plumbing.
A lot of lines of code can get written getting form parameters, query strings, and URL path elements into your logic, and with MVC, this code isn't written by you. If your action has a parameter called "name," MVC will check in all the logical places to populate it, be that a query string, a form value, or possibly the URL path itself. Writing fewer lines of plumbing code means generating fewer bugs.When you write in Razor, you write HTML
If you are a Web Forms developer, you may need to work with front-end developers, and may even number them among your friends. If you do, and you join one for a beer after work, you will learn that front-end devs really don't like working with the markup generated by Web Forms. And with markup that looks like this can you really blame them?
<input name="ctl00$ctl00$MainContent$Content$SearchControls$CardSearchBoxParent$CardSearchBox" type="text" id="ctl00_ctl00_MainContent_Content_SearchControls_CardSearchBoxParent_CardSearchBox" class="textboxinput" onblur="SetCurrentControlBlur(event)" onfocus="SetCurrentControlFocus(event, this);" autocomplete="off" maxlength="50" />
The drag-and-drop, "it's just like creating a Windows App," model of web development was not designed for producing clean markup. Razor, on the other hand, was conceived to read as clean HTML, both in code and in generated output. Basically, you write HTML, and you switch to C# when you need to by throwing in an "@":
<table>
@foreach(var employee in Employees)
{
<tr>
<td>@employee.Name<td>
</tr>
}
</table>
It really shouldn't be this easy.
MVC4 provides Refreshed and modernized default project templates.it is easily to use asp.net application to create interactive website.
ReplyDeleteThanks to share this well informative blog with us.Keep sharing.I will keep share in future.
ReplyDeletePlumber Birmingham, Al
The asp.net platform change the world of web related problems as it gives easy solutions to any kind of API. Hire asp.net developers who are experience as they solve such types in easy manner.
ReplyDelete