Tuesday, August 22, 2017

JQuery date picker in asp.net

Here am going to explained with an example , how to implement jQuery UI DatePicker Calendar with ASP.Net TextBox.
.aspx code
 <script src="../Scripts/jquery-1.12.4.min.js" type="text/javascript"></script>   
 <script src="../Scripts/jquery-ui-1.12.1.min.js" type="text/javascript"></script>  
 <link href="../Content/themes/base/jquery-ui.css" rel="stylesheet" rel="Stylesheet" type="text/css" />  
 <script type="text/javascript">  
   $(function () {  
     $("[id*=txtDate]").datepicker({  
       showOn: 'button',  
       buttonImageOnly: true,  
       buttonImage: 'images/calendar.png'  
     });  
   });  
 </script>  
  <div class="form-inline" role="form">  
    <div class="form-group">  
           <asp:TextBox ID="txtDate" runat="server" ReadOnly = "true"></asp:TextBox>  
           <asp:Button ID="btnSubmit" runat="server" Text="Submit"  
     onclick="btnSubmit_Click" />  
      </div>  
 </div  

Thursday, August 10, 2017

ASP.NET MVC interview questions & answers

What is MVC (Model View Controller)?
Answer: 
MVC is an architectural pattern which separates the UI and Data Model and business logic. It’s divided into three parts, Model, View, and Controller.

1. The Model represents the data and pass it to view (Database objects).
2. The View displays the data and responsible for look and feel of the page (from database).
3. The Controller handles the user input(request) and load appropriate model and view.

What are the advantages of MVC?
Answer: 
Multi view support
Due to the separation of the model from the view, the user interface can display multiple views of the same data at the same time.

Separation of Concerns
Separation of Concerns is one of the core advantages of ASP.NET MVC .Since code-behind concept has been removed from MVC
The MVC framework provides a clean separate logic for the UI, Business Logic, Model or Data.This feature enable code re-usability.
Read More...

Q.Explain “page lifecycle” of an ASP.NET MVC?
When a page is requested first following process are performed by ASP.Net MVC 
Step 1: Routing
In traditional ASP.NET webform application each asp.net page implements the IHTTPHandler interface.
This interface has a ProcessRequest() method that gets called when you request the page. The ProcessRequest() method is responsible for processing the request and generating the response. So in asp.net application it is simple, you request for a page in the url like http://mylocalsite1\default.aspx and then it search for that page on the local disk and execute the processrequest method and generate the html response.
However in MVC application ,request response process is different from webform. In MVC there are no physical page exist for a particular request. All the requests are routed to a special class called Controller. The controller is responsible for generating the response and sending the content back to the browser.
When you build a MVC application you can define a bunch of controllers. Each controller can handle multiple requests. For example, all the following will route to same Controller.
http://mylocalsite1/Controller1/2
http://mylocalsite1/Controller1/3


Question 4: What are different return types of a controller action method?Answer: There are total nine return types we can use to return results from controller to view. The base type of all these result types is ActionResult.
  1. ViewResult (View): View Result is used to return a webpage from an action method.
  2. PartialviewResult (Partialview): PartialViewResult is used to send a part of a view which will be rendered in another view.
  3. RedirectResult (Redirect)RedirectResult is used to redirect to any other controller and action method depending on the URL.
  4. RedirectToRouteResult (RedirectToAction, RedirectToRoute): This return type is used when we want to redirect to any other action method.
Read More...

Question 5 : What are action filters in aspnet mvc?
Answer : ASP.NET MVC provides a very clean way of injecting the pre-processing and post-processing logic for actions and controllers. We can put the pre-processing and post-processing logic is by decorating the actions with attributes which will invoke an attribute class implementing  the filter's logic.
Read More...