Posts

Showing posts with the label MVC

Creating Custom HTML Helpers

Creating custom html code blocks which can be re-used in the entire project. Step1: Add a folder "App_Code" in the root directory. Step2: Add a .cshtml file in the App_Code folder "CustomHelpers.cshml"    @helper   HomeHelper(){         <h1>Home Page Helper</h1>     } Step3: Call the newly added helper code in our existing .cshtml page @{     ViewBag.Title = "Home Page";     Layout = "~/Views/Shared/_Layout.cshtml"; } <h2> Home Page</h2> <div>     @CustomHelper.HomeHelper(); </div>

ASP.NET Routing

Introduction In an ASP.NET application that does not use routing, an incoming request for a URL typically maps to a physical file that handles the request, such as an .aspx file. For example, a request for  http://server/application/Products.aspx?id=4  maps to a file that is named Products.aspx that contains code and markup for rendering a response to the browser. The Web page uses the query string value of  id=4  to determine what type of content to display. In ASP.NET routing, you can define URL patterns that map to request-handler files, but that do not necessarily include the names of those files in the URL. In addition, you can include placeholders in a URL pattern so that variable data can be passed to the request handler without requiring a query string. URL Patterns in MVC Applications URL patterns for routes in MVC applications typically include  {controller}  and  {action}  placeholders. When a request is rec...

Features of the ASP.NET MVC Framework

The ASP.NET MVC framework provides the following features: Separation of application tasks (input logic, business logic, and UI logic), testability, and test-driven development (TDD). All core contracts in the MVC framework are interface-based and can be tested by using mock objects, which are simulated objects that imitate the behavior of actual objects in the application. You can unit-test the application without having to run the controllers in an ASP.NET process, which makes unit testing fast and flexible. You can use any unit-testing framework that is compatible with the .NET Framework. An extensible and pluggable framework. The components of the ASP.NET MVC framework are designed so that they can be easily replaced or customized. You can plug in your own view engine, URL routing policy, action-method parameter serialization, and other components. Extensive support for ASP.NET routing, which is a powerful URL-mapping component that lets you build applications that have compr...