Saturday, May 21, 2016

MVC


What is MVC
  • A MVC is an architectural pattern which separates the business logic and User interface.
  • It is broadly classified into three parts
  • Model:It is a business entity which is used to represent application data and provides the data to view.
  • View:It is responsible for look and feel and views are generated as per model properties.
  • Controller:It is responsible to take end user request,handles the user input data and loads an appropriate view and model.
What is difference between Html.Textbox and Html.Textboxfor in MVC
  • Html.Textbox is not a strongly typed and it does not requires a View.we can hardcore the values.
  • Html.Textboxfor is a strongly typed and it requires a View model.
What is Routing in MVC

  • Routing engine uses the Route table to match the incoming request URL pattern against the pattern defined in the Route table.
  • If any pattern matches with the route table then it forwards the request to the particular controller and the controller action method.
  • We can specify one or more url pattern to the route table with in the Register route method present in Application start event iii Global.asax file.
How can we restrict MVC actions to be invoked by Get or post methods
  • We can decorate the controller action method by "HttpGet" or "Httppost" attribute to restrict the type of Http calls.
What is difference between View data and View bag
  • Both are used to pass the data from controller to view but the difference between them is
  • Viewbag is a dynamic property where as viewdata is a  dictionary object.
  • Boxing and unboxing happens in View data where as it does not happens in Viewbag.
  • View bag performance will be high when compared to View data.
Does Tempdata preserves the data in Next request also
  • Tempdata is available for the current request and for the subsequent request it is available based on the whether the temp data value is read or not.
  • If the temp data value is read then it will not be available for the subsequent request.
What is Partial view in MVC
  • Partial view is similar to User control in ASP.Net.
  • Partial view is also called as a reusable view as it is rendered inside any other view.
  • Partial views can be reside in a shared folder or a specific view folder.
  • If we add a view to a shared folder then it is available for the entire application but if we add a view to a specific view folder then it is available for that view itself.
Difference between Partial and Render partial
  • Render partial returns void and the output will be written directly to the Response stream where as Partial returns "MVCHtmlString" which can be assigned to a variable and manipulate it when required.
  • If we want to change the output then we make use of Partial else Render partial.
  • Render partial performance will be fast as it writes the output directly to the Response stream.
What is the use of Peek and Keep in Tempdata

  • Tempdata will be persistant based on the Four conditions which are shown below
  • Not Read:If the Tempdata value is not read then the value of tempdata will be persistant for the Subsequent request.
  • Normal Read:If we read the value of the Tempdata then the Tempdata value will not be persistent for the subsequent request.
  • Read and Keep:If we read the Tempdata and if we call Keep method then the Tempdata will be persistent.
  • Peek and Read:If we read the Tempdata by using Peek method then the Tempdata value will be persistent for the Next request.
How can we enable Data Annotation validation on Client side
  • It is a Two step process to enable validation on Client side
  • First we need to set ClientValidationenabled and Unobstrusivejavascriptenabled to true in config file.
  • Second we need to add Javascript files which are listed below
  • jquery.1.7.1.min.js
  • jquery.Validate.min.js
  • jquery.Validate.unobstrusive.min.js
When to use ViewResult
  • If a controller action method make sure returns a View then we make use of View Result or else we make use of Sub types present in Action result.
What is difference between UpdateModel and Tryupdatemodel
  • UpdateModel will throws an exception if any validation fails but for Tryupdatemodel it will not throws an exception but it returns a Bool value indication whether validation gets Succeed or not.
Can we overload a MVC action methods
  • Yes we can overload two action methods with same name.If we run directly we will get an ambiguity error.In order to solve the problem we make use of ActionName attribute which will solve the problem.
What are Layout in MVC
  • Layout are very much similar to Master page in Asp.net whicl allows us to maintain a consistent look and behaviour for Multiple views.
How to enable and disable Optimization in MVC
  • To enable or disable optimization we need to write the below code in Application start event which is present in Global.asax file
  • system.web.optimization.BundleTable.EnableOptimizations=false;
Explain the Concept of Scaffolding
  • Scaffolding allows us to generate the CRUD(Create,Read,Update and delete) code and we can change the code as per our requirement.
  • Scaffolding uses Entity framework internally.
How to call one Actionmethod in a controller to another action method in the same controller
  • To call action method with in the same controller we make use of below code
  • return RedirectToAction("Action Name");
  • To call an action method which is present in another controller we make use of below code
  • return RedirectToAction("Action name","Controller Name");
What are Non Action methods in MVC
  • In MVC all methods which are present in controller are treated as Actions.So if we have a method in controller and if we don't want to use it as an action method then we need to decorate a method with "NonAction" attribute.
What is Viewstart page in MVC
  • In content pages or views we make use of Layout in many other views and if we want to use another Layout file we need to change the existing layout which we have used it in another views which is a Time consuming process
  • In order to overcome we make use of Viewstart file and will use layout property in  Viewstart file and refer this file in other views.So if we make any changes in Viewstart will automatically get reflected in all otheer views.
Can a view be shared across multiple controllers
  • Yes we can share a view across multiple controllers by placing the view in Shared folder.
In MVC which action filter executes first and which executes last
  • In MVC Authentication filter will executes first and the Exception filter executes last.
What is the difference between Asp.net wenforms and MVC

ASP.Net web forms
MVC
It consists of Web server controls to design UI. It consists of Html helpers to design UI.
It has state management techniques. It does not contains automatic state management techniques.
It has a file based Url means filename exists in the url.File name should be available in the web server where an application is hosted. It has a route based url means controller name and controller action method will be present in route table and will be invoked when end user sends an incoming request
It has a master page for consistent feel and look. It consists of Layout for consistent feel and look.
It has an user controls for re usability. It consists of partial views for Re usability..
No SOC(Separation of concern) as .aspx page is tightly coupled. It has SOC which separates views and controller


What are Hidden Input and Read only in MVC
  • Hidden Input:It is used when we don't want the end user to see or edit the property but ihe value of the property must be post to server when the form is submitted.Then we make use of Hidden Input attribute.
  • Read Only:It allows us to make the property read only but we can change the property value on the View.But when we post the form to web server model binder will treat the property as read only and will not change the value of the property.
How to change the Action name in MVC
  • "ActionName" attribute allows us to change the controller action name.
What is a Child Actionin MVC

  • An action method which is decorated with ChildActiononly is called as Child action.
  • These child methods does not respond to Url request.If we invoke a method using url  then it will get a compile error.
  • it can be rendered using @Html.Action("Method name");

Sunday, May 8, 2016

Snake Island


Snake island is one of the most deadliest place on the earth which is located in Brazil.This island is filled with 3000 to 4000 snakes live on 110 acre island and you can also find one snake for every six square yards.This island is mostly packed with golden lance head vipers which is one of the most deadliest snake in the entire world.

The snake venom is said to be three to five times stronger which can kill a person in under an hour and can melt human flesh.The Brazilian navy took action and closed the island to the public due to number of snakes and rapid increase in deaths who visits the island.

From 1909 to 1920s,a few people did live on the island in order to run its lighthouse.According to the tale the last lighthouse keeper,along with his family died when a group of snakes entered into his home through the windows.

The only people who are allowed on the island is the research team who receive waivers to collect data.There are only few scientists who have set foot on the snake island.

Stepping into the island requires the legal permission and a doctor need to be present at allowed time.If a person gets bit by a snake on the island an anti venom need to be injected to the person immediately.

Some claim that the snakes were put on the island by pirates to protect their treasure but in reality the population of snakes on the island evolved over 1000 years ago without human intervention.

Saturday, May 7, 2016

Ajax


What is an Ajax
  • Ajax stands for Asynchronous javascript and xml which is used for building better,faster and more interactive Web application.
  • It is also used to exchange the data with server and updating the parts of web page without refreshing the whole page.
  • It uses XMLHttpRequest object to interact with web server,
What are the triggers available in Update Panel
  • There are two types of triggers in Update panel.
  • Postback Trigger:It works with full postback means whole page will be processed
  • Asyncpostback trigger:In this only portions of web page will be processed instead of processing the whole page.
What are Synchronous and Asynchronous Requests
  • Both Synchronous and Asynchronous process the requests and gets the response back from the server.
  • In case of Asynchronous process it will send the request to server and it will not wait for server response.It will continue further process.
  • .But in case of Synchronous process client will send the request to server and will wait until the server sends the response back to client.
How to control the duration of an Ajax request
  • AsyncpostbackTimeout is the property of Scriptmanager to specify the duration for Ajax Request.
  • Default value is 90 Seconds.
    Example:<asp:scriptmanager runat="server" id="scmgr1" AsyncpostbackTimeout ="120"/>

What is an Update Panel in Ajax
  • Ajax Update Panel allows us to avoid the full postback of the page and allows only partial page postbacks.
  • Ajax Update Panel consists of two child tags ContentTemplate and Triggers.
  • ContentTemplate is used to hold the content of the page.It means if we design a page with some controls then those controls need to be wrapped(placed) inside a contentTemplate.
  • Triggers are used to refresh the whole page or the portions of the page based on the trigger we choose.
What are the difference between Ajax and the Javascript


Ajax
Javascript
Ajax sends the request to server and does not wait for the response Javascript sends a request to server and waits for the response from the server.
Ajax minimise the overload on the server Javascript increases the load on the server


How can you find out that an Ajax request ahs been completed
  • Readystate property is used to check whether Ajax request has been completed or not.If Readyproperty is eqyal to Four then the request has been completed.
How can we cancel the XMLHTTPRequest in Ajax
  • Abort() Method can be used to cancel the XMLHTTPRequest in Ajax,
What is a ScriptManager in Ajax
  • ScriptManager allows us to load Ajax related objects on the page.
  • It loads Ajax related scripts and libraries.
  • It provides an access to web services.
  • It also allows us to enable the feature of partial rendering of a web page.
What are different Readystates in XMLHTTPRequest
  • 0 - Ajax request not initialized
  • 1- Ajax request server connection established
  • 2-Ajax request received
  • 3- Ajax request Processing
  • 4- Request finished and response is ready
What is the use of XMLHTTPRequest in Ajax
  • The XmlHttpRequest object is the Key to Ajax.It is an API that can be used by Javascript,Jscript,VBScript and other web browser scripting languages to transfer and manipulate xml data using HTTP,establishing a connection channel between client side and server side.
  • Few of XmlHttpRequest methods are Abort,Open and Send.
  • Few of XmlHttpRequest  properties are Readystate,Status and onReadystatechange.
How to detect Asynchronous Partial page postbacks
  • IsInAsyncpostback is the property of scriptmanager to check whether it is Asynchronous postback or not.It returns a boolean value.
In which assembly Scriptmanager class is defined
  • It is defined in system.web.extensions.dll which is available in GAC.
What is the use of UpdateMode of an UpdatePanel
  • If we are working with Updatepanel then we make use of UpdateMode.
  • If Updatemode is set to Conditional then the content present inside the updatepanel will not get updated every time when any event is raised.
  • If updatemode is set to Always then the content present inside the updatepanel will get refreshed on every postback.It means if we set updatemode to Always then if any event occurs like Button click,dropdown selectedindexchanged events occurs then the content with in the updatepanel is refreshed.Therefore it causes the page performance as the content is refreshing every time.So we need to avoid and make use of Updatemode property to Conditional
What is Scriptmanagerproxy in Ajax
  • ScriptmanagerProxy enables nested components to add scripts and service references if a page already contains a scriptmanager control.
  • If a master page already had a one instance of Scriptmanager and we are referring the master page in content page(.aspx page) then we cannot make use of scriptmanager in content page.In such cases we make use of Scriptmanagerproxy which works same as a Scriptmanager.