Wednesday, 27 August 2014

Difference Between char, varchar & nvarchar DataType


Char DataType

Char datatype which is used to store fixed length of characters. Suppose if we declared char(50) it will allocates memory for 50 characters. Once we declare char(50) and insert only 10 characters of word then only 10 characters of memory will be used and other 40 characters of memory will be wasted.

varchar DataType

Varchar means variable characters and it is used to store non-unicode characters. It will allocate the memory based on number characters inserted. Suppose if we declared varchar(50) it will allocates memory of 0 characters at the time of declaration. Once we declare varchar(50) and insert only 10 characters of word it will allocate memory for only 10 characters.

nvarchar DataType

nvarchar datatype same as varchar datatype but only difference nvarchar is used to store Unicode characters and it allows you to store multiple languages in database. nvarchar datatype will take twice as much space to store extended set of characters as required by other languages.

Thursday, 21 August 2014

Microsoft Visual Studio 2012 Ultimate Product Keys

Here are some product keys:

YKCW6-BPFPF-BT8C9-7DCTH-QXGWC
RBCXF-CVBGR-382MK-DFHJ4-C69G8
YQ7PR-QTHDM-HCBCV-9GKGG-TB2TM

Download Microsoft Visual Studio 2012 Ultimate:
ISO Image (1,5 GB)
Web Installer

Leave a comment if it's working for you.
If not, I'll post new ones.

Monday, 11 August 2014

Encrypt and Decrypt QueryString Parameter Values in ASP.Net Using C#

 

QueryString encrypt from a GridView HyperLink?

 Step-1

<asp:TemplateField HeaderText="View">
      <ItemTemplate>
           <asp:HyperLink id="hlLinkView" Text="View" runat="server"/>
      </ItemTemplate>
</asp:TemplateField>

 Step-2

In RowDataBound Event of GridView

if (e.Row.RowType == DataControlRowType.DataRow)
{
   Label lblPoNoEncrypt = ((Label) e.Row.FindControl("lblPoNo"));
((HyperLink)e.Row.FindControl("hlLinkView")).NavigateUrl = "abc.aspx?Parameter=" + Encrypt(lblAbcEncrypt.Text);

}

Step-3

Add this function


public string Encrypt(string clearText)
        {
            string EncryptionKey = "MAKV2SPBNI99212";
            byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
            using (Aes encryptor = Aes.Create())
            {
                Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
                encryptor.Key = pdb.GetBytes(32);
                encryptor.IV = pdb.GetBytes(16);
                using (MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(clearBytes, 0, clearBytes.Length);
                        cs.Close();
                    }
                    clearText = Convert.ToBase64String(ms.ToArray());
                }
            }
            return clearText;
        }


Step-4:-

At decryption side add this code:

 

private string Decrypt(string cipherText)
        {
            string EncryptionKey = "MAKV2SPBNI99212";
            cipherText = cipherText.Replace(" ", "+");
            byte[] cipherBytes = Convert.FromBase64String(cipherText);
            using (Aes encryptor = Aes.Create())
            {
                Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
                encryptor.Key = pdb.GetBytes(32);
                encryptor.IV = pdb.GetBytes(16);
                using (MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(cipherBytes, 0, cipherBytes.Length);
                        cs.Close();
                    }
                    cipherText = Encoding.Unicode.GetString(ms.ToArray());
                }
            }
            return cipherText;
        }


Step-5:

if (Request.QueryString["Parameter"] != "")
 {
    txt_No.Text = Decrypt(HttpUtility.UrlDecode(Request.QueryString["PoNo"].ToString()));

}

 

Reference: -

Encrypt and Decrypt QueryString Parameter Values in ASP.Net

using C# and VB.Net

 

Monday, 4 August 2014

JSON Interview questions

 

 What is JSON?

If you are lazy to read the complete article see this video created by www.questpond.com  team which explains JSON in a short and sweet manner https://www.youtube.com/watch?v=vrPBtQAxw7c

JSON ( Javascript object notation ) is a simple data exchange format which helps to communicate between JavaScript and server side  technologies like Servlets , JSP , WCF , ASP.Net etc.

The format of JSON is as shown below. The below format represents a “Customer” object with “CustomerCode” and “CustomerName” property.

{"CustomerCode":"1001","CustomerName":"Shiv"}

                          

Now this format can be easily consumed by javascript and transformed in to javascript object. Look at the above figure where we have provided JSON to  javascript variable and you can see how a javascript object is evaluated with a “CustomerCode” and “CustomerName” property.

If you look at the web architecture it has two parts browser and server. On the browser side Javascript is the most prominent and well established language while on server side you have different technologies like JSP, ASP.NET, PHP etc.

                             

So if the server side technologies emit out JSON format which can be easily transformed in to a javascript object that would really ease the communication between multiple server side technologies and javascript language.

AJAX FAQ

AJAX and how does it help?

AJAX stands for Asynchronous JavaScript and XML. There are two prime benefits of AJAX: -
  • It send’s only necessary data to the server. For instance let’s say you have 4 textboxes and on a submit button you want to only send two text box data, AJAX helps in the same.
  • The second benefit is it’s asynchronous. In other words when you click on submit button and until the server processes the request you can do other activities on the site. For instance when you click on send email and until the email is sent, you can start composing a new email at the back ground.
What is the difference between Script Manager and ScriptManager Proxy ? 
Ans : A page can contain only one ScriptManager control. if you have a master content page in ur application and  the master  contains a script manager control, then you can use the ScriptManagerProxy control to add script to content pages

What is AJAX   

AJAX are  client side  UI patterns  . What does it Means ?before that  lets think on simple workflow where client requests  for a resource on server  and server receives the request and response  back to client with resource all this communication is done via HTTP and all page is rendered in HTML .  Now Lets think if you have a information page where user selects a Region and on the basics of selected region list of cities is displayed on dropdownlist   well thats fine it works perfect but here we have one problem for every time when user select a different region then page is posted back to server com-on this increase the network traffic and server load its not a good performance practice .

AJAX resolves this problem by rendering a partial page instead of full page post back to server   . So AJAX is nothing its client side  UI pattern and now its standard for developing robust  web applications  .

How AJAX Work?  

Technically speaking AJAX combines the XMLHTTP components with JavaScript library  it works via  XMLHTTP request to achieve the partial rendering to server instead of full page postback. So What happens when user tries to update or get the information it generates the asynchronous call to server and then server respond with updated data no page refresh will happen.  For example you have to update the total products sold on your grid view  which implements the AJAX so it generate a partial asynchronous call to server and server will respond with updated total

What is Script Manager ?

 ScriptManager  its part of server components it manages the client script for AJAX enable web pages it registers the script for Microsoft AJAX library .

What is Update Panel? 

Well Update panel is most important control it enable the partial page call instead of full page post back Update Panel   has two child tags <contentTemplate>  and< trigger >  content Template is responsible for holding the contents of panel you can put simple test or a control and Trigger tag trigger the call on a particular event so Here you can see markup portion of my code.

Examples:
<table>
        <tr>
            <td>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:DropDownList ID="drpRegions" runat="server" AutoPostBack="True" Height="37px"
                            OnSelectedIndexChanged="drpRegions_SelectedIndexChanged" Width="163px">
                        </asp:DropDownList>
                        <br />
                        Check Cities
                        <br />
                        <asp:DropDownList ID="Cities" runat="server" Height="19px" Width="168px">
                        </asp:DropDownList>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger runat="server" ControlID="drpRegions" EventName="SelectedIndexChanged" />
                    </Triggers>
                </asp:UpdatePanel>
                <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
                    <ProgressTemplate>
                        Please Wait...
                    </ProgressTemplate>
                </asp:UpdateProgress>
            </td>
            <td>
                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                    <ContentTemplate>
                        <asp:DropDownList ID="ddlColors" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlColors_SelectedIndexChanged">
                            <asp:ListItem Value="Red">Red</asp:ListItem>
                            <asp:ListItem Value="Blue">Blue</asp:ListItem>
                            <asp:ListItem Value="Green">Green</asp:ListItem>
                        </asp:DropDownList>
                   
                    <br />
                    <br />
                    Selected color:
                    <asp:Label runat="server" ID="lblSelectedColor" />
                    </ContentTemplate>
                </asp:UpdatePanel>
                <asp:UpdateProgress ID="UpdateProgress2" runat="server" AssociatedUpdatePanelID="UpdatePanel2">
                    <ProgressTemplate>
                        Please wait...
                    </ProgressTemplate>
                </asp:UpdateProgress>
            </td>
        </tr>
    </table>

CS File
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<string> Regions = new List<string>();
                Regions.Add("South");
                Regions.Add("East");
                Regions.Add("West");
                Regions.Add("North");
                Regions.Add("EastWest");
                drpRegions.DataSource = Regions;
                drpRegions.DataBind();
            } 
        }
        protected void drpRegions_SelectedIndexChanged(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(3000);
            List<string> Punjab = new List<string>();
            Punjab.Add("Lahroe");
            Punjab.Add("okara");
            List<string> sindh = new List<string>();
            sindh.Add("Karachi");
            sindh.Add("Quoteata");
            List<string> Buloschistan = new List<string>();
            Buloschistan.Add("Quetta");
            Buloschistan.Add("Cheltan");
            List<string> Serhad = new List<string>();
            Serhad.Add("Peshwar");
            Serhad.Add("Kohat");
            List<string> Kashmir = new List<string>();
            Kashmir.Add("Bagh");
            Kashmir.Add("DheerKot");
            Kashmir.Add("Rawlakot");
            Kashmir.Add("Mirpur");

            if (drpRegions.SelectedValue == "South")
            {
                this.Cities.DataSource = Punjab;
                this.Cities.DataBind();
            }
            else if (drpRegions.SelectedValue == "East")
            {
                this.Cities.DataSource = sindh;
                this.Cities.DataBind();
            }
            else if (drpRegions.SelectedValue == "West")
            {
                this.Cities.DataSource = Buloschistan;
                this.Cities.DataBind();
            }
            else if (drpRegions.SelectedValue == "North")
            {
                this.Cities.DataSource = Serhad;
                this.Cities.DataBind();
            }
            else if (drpRegions.SelectedValue == "EastWest")
            {
                this.Cities.DataSource = Kashmir;
                this.Cities.DataBind();
            }
        }

        protected void ddlColors_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblSelectedColor.Text = ddlColors.SelectedValue;
            lblSelectedColor.BackColor = System.Drawing.Color.FromName(ddlColors.SelectedValue);
            ScriptManager1.AddHistoryPoint("SelectedColor", ddlColors.SelectedValue);
        }

        protected void ScriptManager1_Navigate(object sender, HistoryEventArgs e)
        {
            string color = e.State["SelectedColor"];
            if (!string.IsNullOrEmpty(color))
            {
                lblSelectedColor.Text = color;
                lblSelectedColor.BackColor = System.Drawing.Color.FromName(color);
            }
        }

What is Ajax?
The term Ajax was coined by Jesse James Garrett and is a short form for "Asynchronous Javascript and XML". Ajax represents a set of commonly used techniques, like HTML/XHTML, CSS, Document Object Model(DOM), XML/XSLT, Javascript and the XMLHttpRequest object, to create RIA's (Rich Internet Applications).
Ajax gives the user, the ability to dynamically and asynchronously interact with a web server, without using a plug-in or without compromising on the user’s ability to interact with the page. This is possible due to an object found in browsers called the XMLHttpRequest object.
What is ASP.NET AJAX?
‘ASP.NET AJAX’ is a terminology coined by Microsoft for ‘their’ implementation of AJAX, which is a set of extensions to ASP.NET. These components allow you to build rich AJAX enabled web applications, which consists of both server side and client side libraries.
Which is the current version of ASP.NET AJAX Control Toolkit?
As of this writing, the toolkit version is Version 1.0.20229 (if you are targeting Framework 2.0, ASP.NET AJAX 1.0 and Visual Studio 2005) and Version 3.0.20229 (if targeting .NET Framework 3.5 and Visual Studio 2008).
What role does the ScriptManager play?
The ScriptManager manages all ASP.NET AJAX resources on a page and renders the links for the ASP.NET AJAX client libraries, which lets you use AJAX functionality like PageMethods, UpdatePanels etc. It creates the PageRequestManager and Application objects, which are prominent in raising events during the client life cycle of an ASP.NET AJAX Web page. It also helps you create proxies to call web services asynchronously.
Can we use multiple ScriptManager on a page?
No. You can use only one ScriptManager on a page.
What is the role of a ScriptManagerProxy?
A page can contain only one ScriptManager control. If you have a Master-Content page scenario in your application and the MasterPage contains a ScriptManager control, then you can use the ScriptManagerProxy control to add scripts to content pages.
Also, if you come across a scenario where only a few pages in your application need to register to a script or a web service, then its best to remove them from the ScriptManager control and add them to individual pages, by using the ScriptManagerProxy control. That is because if you added the scripts using the ScriptManager on the Master Page, then these items will be downloaded on each page that derives from the MasterPage, even if they are not needed, which would lead to a waste of resources.
What are the requirements to run ASP.NET AJAX applications on a server?
You would need to install ‘ASP.NET AJAX Extensions’ on your server. If you are using the ASP.NET AJAX Control toolkit, then you would also need to add the AjaxControlToolkit.dll in the /Bin folder.
Note: ASP.NET AJAX 1.0 was available as a separate downloadable add-on for ASP.NET 2.0. With ASP.NET 3.5, the AJAX components have been integrated into ASP.NET.
Explain the UpdatePanel?
The UpdatePanel enables you to add AJAX functionality to existing ASP.NET applications. It can be used to update content in a page by using Partial-page rendering. By using Partial-page rendering, you can refresh only a selected part of the page instead of refreshing the whole page with a postback.
Can I use ASP.NET AJAX with any other technology apart from ASP.NET?
To answer this question, check out this example of using ASP.NET AJAX with PHP, to demonstrate running ASP.NET AJAX outside of ASP.NET. Client-Side ASP.NET AJAX framework can be used with PHP and Coldfusion.
How can you cancel an Asynchronous postback?
Yes you can. Read my article over here.
Difference between Server-Side AJAX framework and Client-side AJAX framework?
ASP.NET AJAX contains both a server-side Ajax framework and a client-side Ajax framework. The server-side framework provides developers with an easy way to implement Ajax functionality, without having to possess much knowledge of JavaScript. The framework includes server controls and components and the drag and drop functionality. This framework is usually preferred when you need to quickly ajaxify an asp.net application. The disadvantage is that you still need a round trip to the server to perform a client-side action.
The Client-Side Framework allows you to build web applications with rich user-interactivity as that of a desktop application. It contains a set of JavaScript libraries, which is independent from ASP.NET. The library is getting rich in functionality with every new build released.
 How can you debug ASP.NET AJAX applications?
Explain about two tools useful for debugging: Fiddler for IE and Firebug for Mozilla.
Can we call Server-Side code (C# or VB.NET code) from javascript?
Yes. You can do so using PageMethods in ASP.NET AJAX or using webservices.
Can you nest UpdatePanel within each other?
Yes, you can do that. You would want to nest update panels to basically have more control over the Page Refresh.
How can you to add JavaScript to a page when performing an asynchronous postback?
Use the ScriptManager class. This class contains several methods like the RegisterStartupScript(), RegisterClientScriptBlock(), RegisterClientScriptInclude(), RegisterArrayDeclaration(),RegisterClientScriptResource(), RegisterExpandoAttribute(), RegisterOnSubmitStatement() which helps to add javascript while performing an asynchronous postback.
Explain differences between the page execution lifecycle of an ASP.NET page and an ASP.NET AJAX page?
In an asynchronous model, all the server side events occur, as they do in a synchronous model. The Microsoft AJAX Library also raises client side events. However when the page is rendered, asynchronous postback renders only the contents of the update panel, where as in a synchronous postback, the entire page is recreated and sent back to the browser.
Explain the AJAX Client life-cycle events
Here’s a good article about the same.
Is the ASP.NET AJAX Control Toolkit(AjaxControlToolkit.dll) installed in the Global Assembly Cache?
No. You must copy the AjaxControlToolkit.dll assembly to the /Bin folder in your application.
On basis of these control only, updatePanel get refreshed then we write in trigger tag
<Triggers>
          <asp:PostBackTrigger ControlID="btnSave" />
         <asp:AsyncPostBackTrigger ControlID="btnDeleteTop" EventName="Click" />
         <asp:AsyncPostBackTrigger ControlID="btnCancel" EventName="Click" />
</Triggers>





ASP.NET MVC (Model View Controller) FAQ



What is Bundling and Minification in ASP.NET MVC?

Bundling

In normal scenario let say for an instance,
  • User makes a request to index action in customer controller.
  • Action method will return a view result.
  • Now the view contains reference to 3 js files and 3 css files.
  • When browser receives the view in response, it comes to know about these references so it will make 6 more requests to server asking for the referenced files.
It will affect the overall response time of the view. To get one complete view browser makes 7 requests (one for view, 3 for js and 3 for css). Now imagine the situation when we have more number of css and js files. 

Bundling is the solution for the same.
It let us combine multiple files into one file at runtime. Using this concept we can create bundles of js and css files. Fewer files mean fewer response times and it means quick response time.

Minification

Normally how we write or JavaScript and css. We follow following rules normally while writing css or js.
  • We use proper indentation
  • We properly add spaces
  • We use enter properly
  • We use meaning full names for defining variables
  • Write comments wherever we write complex logic
What next?  It will affect the size of the file. File size will be increased and thus increased download time.

Solution is Minification. Minification is a technology which will reduces the size of the file at runtime by removing unnecessary whitespaces, comments and shortening variable names.

How to perform bundling and Minification?

Step 1: Add reference of System.Web.Optimization to your project

Step 2: In global.asax create the bundles as follows

BundleTable.Bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-2.1.1.js", "~/Scripts/jquery.validate.js",
"~/Scripts/jquery.validate.unobtrusive.js"));

Step 3: Enable optimization in global.asaxasfollws

BundleTable.EnableOptimizations = true;

Step 4: In the view include bundle as follows

@Scripts.Render("~/bundles/jquery")
 
-----------------

Explain MVC OAuth ?

This MVC Interview question is also asked in a different way “Can we integrate FB and Twitter account authorization with our MVC Application.

One of the most boring process for an end user is registering on a site. Sometimes those long forms and email validation just puts off the user. So how about making things easy by validating the users using their existing facebook / twitter / linkedin / etc    accounts.  So the user uses something which he already has while the site is assured that this user is a proper user.

This is achieved by using MVC OAuth (Open standard for authorization).

                               

Using MVC Oauth is a three step process:-
  • Register your MVC application / website with the external site i.e. facebook , twitter etc. Once you register your app you get an ID and key from the external site. Below is  snap shot of how facebook gives the ID and Key. In FB they term the key as the “App secret”. This process varies from site to site. So FB can have X steps while twitter can X+1.                                          
              

  • Next step is to open “AuthConfig.cs” and you will see lot of readymade code to user your ID and Key. So use the appropriate method as per site and provide the ID and Key.

OAuthWebSecurity.RegisterMicrosoftClient(
                clientId: "",
                clientSecret: "");

OAuthWebSecurity.RegisterTwitterClient(
                consumerKey: "",
                consumerSecret: "");

OAuthWebSecurity.RegisterFacebookClient(
                appId: "",
                appSecret: "");
OAuthWebSecurity.RegisterGoogleClient();

  • Now if you run your application you should get a link to FB login as shown in the below screen. So if you login in FB it will redirect to your MVC application.
        
-----------------

ASP.NET MVC written test Interview question

Below is a MVC written test Interview question paper which was given to senior people to do pre-evaluation.

If you are supposed to do validation in MVC what the best approach?
  • Write the validation in the models.
  • Use data annotations like [required] validator.
You want to implement Ajax in MVC, what will you do?
  • XML HTTP Request
  • Use JSON and JQUERY calls
  • Update panel
You want to create SEO friendly URL’s in MVC?
  • Routing
  • Create custom HTTP handlers and use VERB
Which of the below statements are false?
  • Viewdata helps to pass data from controller to view.
  • Tempdata helps to pass data from controller to controller.
  • Viewdata helps to pass data from view to controller.
If you want to bind two models with a view?
  • Not possible with MVC
  • Use ViewModel
You want to emit out JSON from MVC?
  • Serialize the object and pass it back
  • Use JSONResult
  • Use WCF and emit out JSON
How is the hierarchy in Angular?
  • Controller -> App -> Model
  • App -> Controller -> Model
You want to compress your JavaScript files in MVC?
  • Use Winrar
  • Use Bundling and minification
You want to make cross domain JSON calls :-
  • Enable cross domain in web.config file of JSON project.
  • Use [CrossDomain] attribute.
  • CORS does not work by design
What is the use of filters ?
  • Filters and queries SQL
  • Does preprocessing and post processing logic
Can we do pessimistic locking in EF ?
  • Yes
  • No
You want to render MVC ASCX ?
  • Use RenderAction
  • Use RenderPartial
Is it possible to create a custom view engine like Razor ?
  • No
  • Yes
How to enable Lazy loading in EF ?
  • Use include
  • Use stored procedures.
  • None of the above , it enabled by default.
What is false about WebAPI ?
  • It does content negotiation.
  • Emits out JSON and XML
  • Emits out WCF SOAP
You have heavy Action which is taking lot of time ?
  • Create that site on a different app pool.
  • Use Delegates
  • Use Async controllers.
-----------------

Explain the difference between layout and master pages ? ( MVC Razor interview questions)

Layout are like master pages in ASP.NET Web form. Master pages give a standard look and feel for Web form views while layout gives standard look and feel or acts like a template for razor views.

How to apply layout to Razor views?

So first we need to create a template file as shown in the below code.


And then apply this template to the view as shown below and display data in those respective sections.


You can go through these  100 MVC interview question with answers fromhttp://www.codeproject.com/Articles/556995/MVC-interview-questions-with-answers
----------------

Explain MVC model binders ? ( ASP.NET MVC interview questions)

June 13, 2014 at 1:01pm
Model binder maps HTML form elements to the model. It acts like a bridge between HTML UI and MVC model. 
                                               

Take the below simple HTML form example :-

<formid="frm1" method=post action=”/Customer/SubmitCustomer”>
                   Customer code :- <inputname="CCode"type="text"/>
                   Customer name :- <inputname="CName"type="text"/>       
          <input type=submit/>
</form>

Now this form needs to fill the below “Customer” class model. If you see the HTML control name they are different from the class property name. For example HTML textbox control name is “CCode” and the class property name is “CustomerCode”.  This mapping code is written in HTML binder classes.

publicclassCustomer
{
publicstring CustomerCode { get; set; }
publicstring CustomerName { get; set; }
}

To create a model binder we need to implement “IModelBinder” interface and mapping code needs to be written in the “BindModel” method as shown in the below code.

publicclassCustomerBinder : IModelBinder
{
publicobject BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
HttpRequestBase request = controllerContext.HttpContext.Request;

string strCustomerCode = request.Form.Get("CCode");
string strCustomerName = request.Form.Get("CName");

returnnewCustomer
            {
                CustomerCode = strCustomerCode,
                CustomerName = strCustomerName
            };
}
}

Now in the action result method we need to use the “ModelBinder” attribute which will attach the binder with the class model.

publicActionResult SubmitCustomer([ModelBinder(typeof(CustomerBinder))]Customer obj)       
{

return View(“DisplayCustomer”);
}

This MVC interview question was provided by questpond which conducts ASP.NET MVC training . In case you are new to MVC you can start from questpond video which is shown below.
----------------

MVC and .NET learning tutorials for components of MVC and how do you perform unit testing in MVC?

Components of MVC: -

MVC consist of Model, View and Controller.
  • View represents UI of the application with which end user interacts.
  • Model represents the Business Data and business Logic
  • Controller handles the User Interaction logic.
Unit testing: -

Unit testing means to test each and every small logic in our code in an independent and automated manner. Also see tutorial video on .NET  explaining practically on Simple Unit Testing: -


Performing unit testing in MVC: -

When we say logic there are different kinds of logic. Business Logic, Database logic, User Interaction Logic, Presentation logic and Data Transformation logic,
  • In MVC Model or Business Logic, is simply a class with some functions. So unit testing of it is not a big deal. It can be done easily using traditional class library unit testing approach.
  • User interaction logic resides in Controller which is also a simple class. It can be tested with no much effort. Click herehttp://www.codeproject.com/Articles/763928/MVC-Unit-Testing-Unleashed#TestingInMVC to read more about controller unit testing
  • Database logic location will be different for different people. Some people put them in the Model whereas some consider it as a separate layer in an application. In either case it’s going to be simple class library and hence falls under traditional class library unit testing.
  • Remaining is Presentation Logic and Data Transformation logic. Best example of presentation logic is displaying different controls in different colours based on some dynamic value. Data Transformation logic means, converting format of data to be displayed. Example we have DateOBirth and we want to display age. 
Such kind of logic always need to be written inside the view. Unit testing of view is not an easy thing.
Solution is Implement ViewModel concept and take out these two logic from view and put it as a separate class.
--------------

-------------