Friday, July 7, 2017

ASP.Net MVC - Custom Model Binding

custom-model-binding
In last article, we have discussed about what is ASP.NET Model binding and saw a basic introduction to the Model Binder. In this post we will see creating Custom Model Binding in ASP.Net MVC with simple example.

Model Binder in ASP.NET MVC

For model binding MVC uses the following types-

IModelBinder interface - This defines methods that are required for a Model Binder, like the BindModelAsync method. This method is responsible for binding a model to some values using ModelBindingContext

IModelBinderProvider interface - This interface contains methods that enables dynamic implementation of model binding for classes which implement the IModelBinder interface. This is used to manage the custom binder for the type of data posted by the end-user in views.

Creating Custom Model Binder

We creating our custom model binder by implementing the IModelBinder and IModelBinderProvider interfaces. Let see how we will do that.

Note :I have used ASP.Net MVC Core project here.All the codes are in ASP.Net MVC Core.

Monday, July 3, 2017

ASP.Net MVC Model Binding

 Model Binding

Model Binding

What is Model Binding?

Model Binding in ASP.Net MVC maps the data from HTTP request to action method parameters. These parameters may be simple types such as string, integer or they may be complex type. It is a great feature as it relieves developer from writing all the type casting and “HTML-Model mapping code”. The Model binder is capable of retrieving the data from HTML form variables, POSTed variables and files, query string parameters and the values added in the routes.


How model binding works?

When MVC receives HTTP request, it routes the request to a specific action method of a controller. It determines which action method is going to execute based on what is in the route data, then it maps values from the HTTP request to action method’s parameter(s). For ex. Consider the below URL-

http://abc.com/books/edit/2

Wednesday, October 28, 2015

ASP.NET 4.5 Architecture


Request Processing 


  1. IIS gets the request
  2. Looks up a script map extension and maps to aspnet_isapi.dll
  3. Code hits the worker process (aspnet_wp.exe in IIS5 or w3wp.exe in IIS6)
  4. .NET runtime is loaded
  5. IsapiRuntime.ProcessRequest() called by non-managed code
  6. IsapiWorkerRequest created once per request
  7. HttpRuntime.ProcessRequest() called with Worker Request
  8. HttpContext Object created by passing Worker Request as input
  9. HttpApplication.GetApplicationInstance() called with Context to retrieve instance from pool
  10. HttpApplication.Init() called to start pipeline event sequence and hook up modules and handlers
  11. HttpApplicaton.ProcessRequest called to start processing
  12. Pipeline events fire
  13. Handlers are called and ProcessRequest method is fired
  14. Control returns to pipeline and post request events fire

Tuesday, October 6, 2015

SQL : Sql Query Execution Order

Most programming languages executes set of statements from Top to Bottom but SQL Server executes set of statements in a logical order which is uniquely decides by the SQL Server in a predefined order known as Logical Query processing phase.

Introduction

When we are developing an application our concern mostly related to the code optimization which enhances the performance of application. When we are talking about an application it has broadly divided into two part one is the our code written in any programming language and other is the code written in database which executes at database level and return the results to our application.
In real world most application facing the performance issue which can be improved by code optimization. Here we will talk about the SQL query optimization.Most programming languages executes set of statements from Top to Bottom but SQL Server executes set of statements in a logical order which is uniquely decides by the SQL Server in a predefined order known as Logical Query processing phase.

C# : What is New in C# 6.0?


New features in C#6.0
In this post we will see the newly added features in C# 6.0. In C# 6.0 some very cool features has been added like "Auto-property Enhancements", "Primary Constructors", "Expressions as Function Body", "Use of Static", "Exception Filters", "inline declarations", "nameof Expressions", "Null-conditional Operators", "String interpolation", "Await in catch and finally".





Introduction

Here, you will find nine new cool features of C# 6.0:

  1. Auto-property Enhancements
  2. Parameters on Classes and Structs
  3. Using Static
  4. Exception Filters
  5. Null-conditional Operators
  6. Index Initializers
  7. $ sign
  8. String Interpolation
  9. nameof Expression
  10. Await in catch and finally block
^ Scroll to Top