Ans: Model–view–controller (MVC) is a software design pattern for implementing user interfaces on computers. It divides a given software application into three interconnected parts, so as to separate internal representations of information from the ways that information is presented to or accepted from the user.
Ans: A Model , which represents the underlying, logical structure of data in a software application and the high-level class associated with it. This object model does not contain any information about the user interface.
Ans: Below are the steps how control flows in MVC (Model, view and controller) architecture:-
1.All end user requests are first sent to the controller.
2.The controller depending on the request decides which model to load. The controller loads the model and attachesthe model with the appropriate view.
3.The final view is then attached with the model data and sent as a response to the end user on the browser
Ans: In MVC there are 12 results. Among them ActionResult class is a base class for all action results. The 11 sub classes are given bellow:
Ans: Routing is a way to process the incoming url that is more descriptive and give desired response. A route is a URL pattern that is mapped to a handler. The handler can be a physical file, such as a .aspx file in a Web Forms application. A handler can also be a class that processes the request, such as a controller in an MVC application. To define a route, you create an instance of the Route class by specifying the URL pattern, the handler, and optionally a name for the route.
Ans: MVC is an evolution of a three layered traditional architecture. Many components of the three layered architecture are the part of MVC.
A fundamental rule in three tier architecture is the client tier never communicate directly with the data tier. In a three-tier model all communication must pass through the middle tier.
MVC architecture is triangular. The view sends updates to the controller, the controller updates the model, and the view gets updated directly from the model.
Ans: Action Filters: Action filters are used to implement logic that gets executed before and after a controller action executes.
Ans: MVC architecture is suited for web application than windows. For window application MVP i.e. “Model view presenter”is more applicable.IfyouareusingWPFandSLMVVMismoresuitableduetobindings
Ans: Razor ia an ASP MVC view engine that lets you to write server-based code in your view to create a dynamic content the render it into availd HTML
Ans: For Windows authentication, at first we need to change the web.config file and set the authentication mode to Windows. A sample code for that is given bellow:
<authentication mode="Windows"/>
<authorization>
<deny users="?"/>
</authorization>
Then in the controller or on the action, we can use the Authorize attribute which specifies which users have access to these controllers and actions. A sample code for that is given bellow, where only the user “Administrator” can access it.
[Authorize(Users= @”WIN-3LI600MWLQN\Administrator”)]
public class StartController : Controller
{
//
// GET: /Start/
[Authorize(Users = @"WIN-3LI600MWLQN\Administrator")]
public ActionResult Index()
{
return View("MyView");
}
}
Ans: ViewData: It is available for the current request only and requires typecasting for complex data type.
ViewBag: Dynamic property that takes advantage of the new dynamic features in C# 4.0, also available for the current request only. If redirection occurs, then its value becomes null and doesn’t require typecasting for complex data type.
TempData: used to pass data from the current request to the next request, keeps the information for the time of an HTTP Request. This means only from one page to another.
Ans: Any web application first understands the request and depending on type of request, it sends out appropriate response. MVC application life cycle is not different, it has two main phases, first creating the request object and second sending our response to the browser.
The request object creation has four major steps,
Step 1: Fill route
Every MVC request is mapped to route table which specifies which controller and action to be invoked. If it is the first request, it fills the route table with route collection. This filling of route table happens in the global.asaxfile.
Step 2: Fetch route
Depending on the URL sent "UrlRoutingModule" searches the route table to create "RouteData" object. RouteData has the details of which controller and action to invoke.
Step 3: Request context created
The "RouteData" object is used to create the "RequestContext" object.
Step 4: Controller instance created
The coming request object is sent to "MvcHandler" instance to create the object of controller class. Once the controller class object is created, it calls the "Execute" method of the controller class.
Creating Response object:
This phase has two steps - Executing the action and finally sending the response as a result to the view.
Ans: HtmlHelper class generates html elements using the model class object in razor view. It binds the model object to html elements to display value of model properties into html elements and also assigns the value of the html elements to the model properties while submitting web form. So always use HtmlHelper class in razor view instead of writing html tags manually.
Ans: In MVC, bundling and minification helps us improve request load times of a page. It increases the performance of the applications.
Ans: REST stands for REpresentational State Transfer. REST is web standards based architecture and uses HTTP Protocol for data communication. It revolves around resource where every component is a resource and a resource is accessed by a common interface using HTTP standard methods
In REST architecture, a REST Server simply provides access to resources and REST client accesses and presents the resources. Here each resource is identified by URIs/ global IDs. REST uses various representations to represent a resource like text, JSON and XML. Now a days JSON is the most popular format being used in web services.
Ans: When this note was written, four versions where released of MVC. MVC 1 , MVC 2, MVC 3 and MVC 4. So the latest isMVC 4
Ans: It enables us to cache the content returned by any controller method so that the same content does not need to be generated each time the same controller method is invoked. Output Caching has huge advantages, such as it reduces server round trips, reduces database server round trips, reduces network traffic etc. The main purpose of using Output Caching is to improve the performance of the application.
Ans: Below is a detail table of differences. But during interviewit’s difficult to talk about all of them due to timelimitation.So I have highlighted important differences which you can run through before the interviewer.
MVC 2
MVC 3
MVC 4
Client-Side Validation TemplatedHelpers Areas AsynchronousControllers
Html.ValidationSummaryHelper Method DefaultValueAttribute inActionMethod Parameters Binding BinaryData with Model Binders DataAnnotationsAttributes Model-Validator Providers NewRequireHttpsAttribute Action FilterTemplated Helpers Display Model-LevelErrors
Razor
Readymade project templates
HTML 5 enabled templatesSupportfor Multiple View EnginesJavaScriptand Ajax
Model Validation Improvements
ASP.NET Web API
Refreshed and modernized defaultproject templatesNew mobile projecttemplate
Many new features to support mobileapps
Enhanced support for asynchronousmethods
Ans: Bundling and minification are two techniques you can use to improve request load time.
Bundling helps you to download files of same type using one request instead of multiple requests. This way you can download styles and scripts using less requests than it takes to request all files separately.
Minification performs a variety of different code optimizations to scripts or css, such as removing unnecessary white space,comments and shortening variable names to one character.
Ans: Minification is a process to remove the blank space, comments etc.
The implementation of minification is as like as bundling. That means when we implement bundling minification is also implemented automatically. A sample JavaScript codes with comments:
// This is test comments
var x = 5;
x = x + 2;
x = x * 3;
After implementing minification the JavaScript code looks like:
var x=5;x=x+12x=x*3
Ans: A partial view is a component built by the developer to re-use a bulk of HTML that can be inserted into an existing DOM. Most commonly, partial views are used to componentize Razor views and make them easier to build and update. Partial views can also be returned directly from controller methods.
Ans: All static files are now (by default) located inside of wwwrootfolder. You store your CSS, JS, images, fonts and others static content inside of it.
Related Interview Questions...
ASP.Net Web API Essentials using C# Interview Questions
VB.NET Interview Questions and Answers
.Net Interview Questions and Answers
ASP.NET Interview Questions and Answers For Experienced
ASP.NET Interview Questions and Answers