Showing posts with label MVC 4. Show all posts
Showing posts with label MVC 4. Show all posts

Tuesday, 13 May 2014

Click Here to Download CustomRazorHelperClass.zip

It is very easy to write custom razor helper class. After creating custom razor helper class, we can use these classes anywhere in MVC Application.

Here is step by step explanation of creation of razor helper class.

STEP 1 :
First create MVC web application if you do not have MVC Web Application

STEP 2 :
Now Add new "App_Code" folder. In this folder add MVC Razor View page (MVC 4 View Page (Razor)).

To do this, you need to do right click on 'App_Code' folder and click on "Add New Item" menu. It will display dialog box to add new item. After that add 'MVC 4 View Page (Razor)' Page. Give it named like 'CustomRazorHelper.cshtml'.

Now we add one method name 'ToTitleCase', this method makes first character upper case of given statement and make rest of the characters lower case.

Wednesday, 23 April 2014

Click Here to Download PlayVideoInMVC.zip

It is very easy to play or display video in ASP.NET MVC using HTML5. We can do this using custom action filter in MVC. We can play various files like MP4, Ogg, WebM, etc. format.

Here are step by step tutorial to play video in ASP.NET MVC using HTML5.

Here is example for this.

Friday, 24 January 2014

Click Here to Download ImplementIValidateObjectInterfaceInMVC.zip Example.

We can validate model itself by implementing IValidatableObject Interface. For validation you need to implement 'Validate' method of IValidatableObject Interface.

Here is some difference from the attribute validation version.
  • In this for validation method is 'Validate' instead of 'IsValid' and also return type and parameter is different.
  • The return type for Validate is an IEnumerable<ValidationResult>, because the logic inside this method is validating the entire model and might need to return more than a single validation error.
  • No parameter is passed to Validate because you  can directly access model properties because this Validate method is inside model.

Here is example for this.

Wednesday, 1 January 2014

Click Here to Download CustomAnnotationInMVC.zip Example.

You can write your own custom annotations in MVC 4.
Here we can do custom validation using custom annotations. Custom annotations validation derive from the ValidationAttribute base class. This base class available in 'System.ComponentModel.DataAnnotations' namespace. ValidationAttribute class is abstract class.

For custom validation you need to write your own class and inherit ValidationAttribute class. After that, you need to override IsValid Method. IsValid Method has two parameters 'Value' and 'ValidationContext'.

  • Value : Which contains your data, which is going to validate.
  • ValidationContext : This parameter is very important. This content information like model object instance, model type friendly display name and other information
In this method you write your own logic for validate data and return result. If value is validate at that time you need to return this 'ValidationResult.Success' else you return result like 'return new ValidationResult(your custom error message)'

Saturday, 30 March 2013

Click Here to Download WebAPICRUDOperation.zip


In this article we are demonstrating how Insert, Update, View and Delete operation works in Output using HTTP service.
We can also call as CRUD (Create, Read, Update, Delete) Operation.

In this WebAPI example we are using following HTTP Methods for CURD Operations.

  • GET method retrieves the data or resources at a specified URI.
  • PUT method updates the data or resource at a specified URI.
  • POST method send data to the specified URI.
  • DELETE method deletes a resource at a specified URI.

Now we are creating project step by step.

STEP 1 :

Create a Web API Project.

Friday, 8 March 2013

Click Here to Download WebAPIProject_First.zip


ASP.NET Web API is a framework for developing web APIs on top of the .NET Framework. Web API serves data on HTTP. HTTP service is so powerful and compatible with various clients and platform.

Web API uses in Mobile devices, various browsers and in desktop applications to get or post data.

In this project or tutorial, we will use ASP.NET Web API to create a web API that returns a list of customers and depend on parameters we provide. We are getting results direct on browser and also display in web page with use of jQuery.

As we are developing this project in new framework following are the prerequisite:
Following is the requirement :

This example requires Visual Studio with ASP.NET MVC 4.

We can use any following:
    Visual Studio 2012
    Visual Studio Express 2012 for Web
    Visual Studio 2010 with ASP.NET MVC 4 installed.
    Visual Web Developer 2010 Express with ASP.NET MVC 4 installed.

If you are using Visual Studio 2010 or Visual Web Developer 2010 Express, you will need to install ASP.NET MVC 4 separately.


This project we developed in Visual Studio 2012.

Here is the step-by-step explanation of how to create Web API Project.

STEP 1 :