Creating a Facebook app using ASP.NET MVC Facebook Templates and ...
Creating a Facebook app using ASP.NET MVC Facebook Templates and ... | asp net web forms application tutorial

What You Should Wear To Asp Net Web Forms Application Tutorial | Asp Net Web Forms Application Tutorial

Posted on

C# Corner

Creating a Facebook app using ASP.NET MVC Facebook Templates and ..
Creating a Facebook app using ASP.NET MVC Facebook Templates and .. | asp net web forms application tutorial

How to use MEF to add validation aphorism apparatus to an ASP.NET MVC Web application.

The Managed Extensibility Framework (MEF) has been allotment of the .NET Framework back .NET 4.0. There are abounding tutorials beyond the Web on how to use MEF with Windows Forms, WPF and Windows Store. MEF allows an appliance to be continued through a set of apparatus that may either be alien or exported. Today I’ll appearance how to add business aphorism plug-ins to a new ASP.NET MVC application.

To get started, actualize a new ASP.NET MVC 4 Internet Appliance in Visual Studio 2012 or 2013. Again install the MEF.MVC4 NuGet package, as apparent in Figure 1.

How to do it..
How to do it.. | asp net web forms application tutorial

Next,  add a new Chic Library called BusinessRules to the Visual Studio solution. The BusinessRules activity will accommodate the IValidate interface and some abject business aphorism apparatus that will alien in the MVC project. Again add a new chic called ValidationResult that has an IsValid boolean acreage and an ErrorMessage cord property. Your ValidationResult chic should attending like this:

Next, add the IValidate all-encompassing interface. This interface defines a Validate adjustment that accepts a all-encompassing ascribe blazon and allotment a ValidationResult:

Now add the IValidateMetaData class, which contains a Name cord property:

c# - Create and Edit ASP.net web forms project on VisulaStudio 12 ..
c# – Create and Edit ASP.net web forms project on VisulaStudio 12 .. | asp net web forms application tutorial

Now it’s time to add the aboriginal validation component, which validates a user’s email address. The ValidateEmail chic uses a approved announcement to validate the email, and allotment a ValidationResult article with IsValid set to apocryphal and an absurdity bulletin set if the email is not valid. The ValidateEmail chic exports the IValidate<string> interface and exports a metadata name of “Email”:

It’s now time to add the ValidateUsPhone class. It’s actual agnate to the ValidateEmail class, except is uses a U.S. buzz cardinal approved expression. I set the consign metadata name to “U.S. Phone” for the class:

Now that the BusinessRules chic is completed, it’s time to wire up MEF in the MVC activity to amount the validation rules. Accessible up the MefConfig chic file, amid at App_State/MefConfig.cs, and adapt the ConfigureContainer method:

Create the Project | Microsoft Docs - asp net web forms application tutorial
Create the Project | Microsoft Docs – asp net web forms application tutorial | asp net web forms application tutorial

The business aphorism apparatus are loaded into MEF through the businessRulesCatalog. In addition, I amount in any MEF apparatus independent aural the MVC activity accumulation through the assemblyCatalog object. The catalogs article is an AggregateCatalog accumulating that contains both the active accumulation and the business rules assembly. Lastly, a new CompositionContainer is created from the AggregateCatalog and returned.

The completed MefConfig chic book should now attending like this:

Next, accessible up the Global.asax.cs book and alarm MefConfig.RegisterMef() from aural the Application_Start method:

How to create asp net web forms application using C# (Part 12) - YouTube - asp net web forms application tutorial
How to create asp net web forms application using C# (Part 12) – YouTube – asp net web forms application tutorial | asp net web forms application tutorial

The aftermost footfall is to amount all the validation rules into an MVC form. Actualize a ViewModels agenda aural the MVC project, again add a new chic called ValidationFormModel to the ViewModels folder. The ValidationFormModel chic contains backdrop for anniversary of the ascribe fields and labels for the validation analysis form.

There’s an Ascribe acreage that will abundance the user’s amount to validate. The Rules acreage will accommodate all the accurate validation rules alien through MEF. The Aphorism acreage will be loaded with the user’s called rule, and the StatusLabel acreage will acquaint the user if their submitted ascribe is valid:

Now that the appearance archetypal chic is completed, let’s set up the Razor appearance for the analysis page. Accessible up the Home controller’s Index activity appearance at Views/Home/Index.cshtml, and archetype in the afterward markup:

c# - Create and Edit ASP.net web forms project on VisulaStudio 12 ..
c# – Create and Edit ASP.net web forms project on VisulaStudio 12 .. | asp net web forms application tutorial

The final footfall is to apparatus the Index activity on the HomeController class. Aboriginal I add application statements for MEF and the ViewModels namepsaces:

Next I add Validators acreage that uses the MEF ImportMany aspect to acceptation all validators that apparatus IValidate<string>:

Again I apparatus the Index HttpGet action, which creates a new ValidationFormModel with a loaded Rules drop-down account and endless it into the Index view:

ASP.NET C# Tutorials - Introduction To ASP
ASP.NET C# Tutorials – Introduction To ASP | asp net web forms application tutorial

Finally, I apparatus the HttpPost Index ambassador activity that accepts a ValidationFormModel. Aboriginal I get the called aphorism from the Validators accumulating by name:

What You Should Wear To Asp Net Web Forms Application Tutorial | Asp Net Web Forms Application Tutorial – asp net web forms application tutorial
| Pleasant to help the blog, within this time We’ll show you regarding asp net web forms application tutorial
.

Getting Started with ASP.NET 12.12 Web Forms and Visual Studio 12 ..
Getting Started with ASP.NET 12.12 Web Forms and Visual Studio 12 .. | asp net web forms application tutorial
Creating an ASP Web Forms Application in Visual Studio - YouTube - asp net web forms application tutorial
Creating an ASP Web Forms Application in Visual Studio – YouTube – asp net web forms application tutorial | asp net web forms application tutorial
Getting Started with ASP.NET 12.12 Web Forms and Visual Studio 12 ..
Getting Started with ASP.NET 12.12 Web Forms and Visual Studio 12 .. | asp net web forms application tutorial
ASP.NET Tutorial 12- How to Create a Login website - Creating ..
ASP.NET Tutorial 12- How to Create a Login website – Creating .. | asp net web forms application tutorial
Getting Started with ASP.NET 12.12 Web Forms and Visual Studio 12 ..
Getting Started with ASP.NET 12.12 Web Forms and Visual Studio 12 .. | asp net web forms application tutorial

Gallery for What You Should Wear To Asp Net Web Forms Application Tutorial | Asp Net Web Forms Application Tutorial