ASP.NET MVC 4 Cheat Sheet

Application Folders


It has configuration classes to reduce clutter code in the Global.asax Application_Start method. It contains following files:

- AuthConfig.cs

Related to security settings, including sites for OAuth login.

- BundleConfig.cs

Related to register bundles for the bundling and minification

- FilterConfig.cs

To register global MVC filters.(by default HandleErrorAttribute is registered)

- RouteConfig.cs

Related to MVC Route configuration

- WebApiConfig.cs

Used to register Web API routes and configuration settings


An MVC structure inside the application to partition our web application into smaller parts.


To put CSS and other static contents


Contains the controller classes


For images, It is being referenced from the Content\Site.css by default.


Contains view model and domain model classes.


Stores all JavaScript libraries and files


Related to the display of the application (UI).

Html Helpers

used to render (modify and output) HTML form elements


Output: <a href=".."...>..</a>


Output: <form ...>


Output: <input type="checkbox" .../>


Output: <select ..> .. </select>


Output: </form>


Output: <input type="hidden" ... />


Output: <select multiple ...>...</select>


Output: <input type="password" ... />


Output: <input type="radio" .. />


Output: <textarea...>...</textarea>


Output: <input type="text" ... />


Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object.


To display an error for a particular field in the ModelState dictionary


To generate a URL to a specific route

View Related & Others

@{ Layout = "..."}

To define layout page Equivalent to master-page

@model <StrongModelType>

To define strongly-typed model

@section <name> { }

To define named section


Used in layout as a placeholder for view's entire content.


Renders the content of one page within another page.


In layout pages, renders the content of a named section.


Returns a value that indicates whether the specified section is defined in the page.


To create named content sections in content page.


To define a helper which create a reusable code snippet.


To define a function ( pure server-side methods)that can be reused within the view.


Dynamic property, used to pass data between a Controller and a View


To pass data between a Controller and a View via special Dictionary class


To pass State Between Action Methods

Action Method Result


generic return value for an action and is used to perform a framework-level operation on behalf of the action method.


To return a user-defined content type that is the result of an action method.


To return nothing from a Controller action


Sends the contents of a binary file to the response.


Sends the contents of a file to the response.


To return the content of a file to the browser


Sends binary content to the response by using a Stream instance.


To return 404 status-code to indicate that the requested resource was not found.


To return specific HTTP response status code and description.


To return 401 status code to indicate unauthorized HTTP request.


To return a serialized JSON object.


To return a script that can be executed on the client.


To render a partial view (fx. just a user control)


To redirect to a specified URI.


to redirect to a route


Represents the result of binding a value (such as from a form post or query string) to an action-method argument property, or to the argument itself.


Represents the result of locating a view engine.


To Render a view as a Web page.



To specify HTTP verbs an action method will respond to.


To define the name of an action


to populate the ModelMetadata.AdditionalValues dictionary for a model property.


To allow HTML markup during model binding by skipping request validation for the property.


To set the timeout value, in milliseconds, for an asynchronous method.


To restrict access by callers to an action method.


To indicate that an action method should be called only as a child action.


to handle an exception that is thrown by an action method.


To render a property or field value as a hidden input element.


to restrict an action method to handle only HTTP DELETE requests.


to restrict an action method to handle only HTTP Get requests.


to restrict an action method to handle only HTTP Post requests.


to restrict an action method to handle only HTTP Put requests.


to associate a model type to a model-builder type.


To set the timeout to infinite (never).


To indicate that a controller method is not an action method.


To mark an action method whose output will be cached.


It is used to invoke the server-based validation from client side.


It forces an unsecured HTTP request to be re-sent over HTTPS.


Specifies the session state of the controller.


To mark action methods whose input must be validated.

Data Annotations for Model


Lists fields to exclude or include when binding parameter or form values to model properties


To compare two properties.


To Specify that a data field value is a credit card number.


used for formatting purposes, not for validation.

[DisplayName (...)]

Defines the text we want used on form fields and validation messages


To validate an email address

[FileExtensions(Extensions = "jpg,png...")]

To Validate file name extensions.


To denote one or more properties that uniquely identify an entity.


To define the maximum length of array or string data allowed in a property.


To define the minimum length of array of string data allowed in a property.


To Specify for phone number using a regular expression.

[Range (...)]

Gives a maximum and minimum value for a numeric field


To specify that a data field value must match the specified regular expression.

[Required (...)]

Indicates that the property is a required field


Defines a maximum length for a string field


Allows hiding fields from editor forms


It provides URL validation.



Represents the base class for filter attributes.


Represents an attribute that is used to influence the selection of an action method.


Represents an attribute that affects the selection of an action method.


It invokes a custom model binder.


base class for action and result filter attributes.

Html Helpers


It generates a hidden form field (anti-forgery token) that is validated when the form is submitted.


To convert the specified attribute value to an HTML-encoded string.


To convert the specified value to an HTML-encoded string.

@{ Html.EnableClientValidation(); }

To enables or disables client validation

Html. EnableUnobtrusiveJavaScript

To enables or disables unobtrusive JavaScript.


To format value


To return markup that is not HTML encoded.


To render a partial view into a string.


writes directly to the response output stream instead of returning a string.


executes a separate controller action and returns as string


executes a separate controller action and render the result directly to the Response