Other Flashcards
SOLID, best practices
Who is the CTO of Ameriflex
Matt Palubicki
Who is the CEO of Ameriflex?
William Short
What is ASP.NET MVC?
ASP.NET MVC is a web application Framework. It is light weight and highly testable Framework. MVC separates application into three components — Model, View and Controller.
Can you explain Model, Controller and View in MVC?
Model — It’s a business entity and it is used to represent the application data.
Controller — Request sent by the user always scatters through controller and it’s responsibility is to redirect to the specific view using View() method.
View — It’s the presentation layer of MVC.
Can you explain the page life cycle of MVC?
→App initialization →Routing →Instantiate and execute controller →Locate and invoke controller action →Instantiate and render view.
What are the advantages of MVC over ASP.NET?
→Provides a clean separation of concerns among UI (Presentation layer), model (Transfer objects/Domain Objects/Entities) and Business Logic (Controller).
→Easy to UNIT Test.
→Improved reusability of model and views. We can have multiple views which can point to the same model and vice versa.
→Improved structuring of the code.
What is Separation of Concerns in ASP.NET MVC?
It’s is the process of breaking the program into various distinct features which overlaps in functionality as little as possible. MVC pattern concerns on separating the content from presentation and data-processing from content.
What is Razor View Engine?
Razor is the first major update to render HTML in MVC 3. Razor was designed specifically for view engine syntax. Main focus of this would be to simplify and code-focused templating for HTML generation. Below is the sample of using Razor:
@model MvcMusicStore.Models.Customer
@{ViewBag.Title = “Get Customers”;}
<div> <h3><em>@Model.CustomerName</em> </h3></div>
What is the meaning of Unobtrusive JavaScript?
This is a general term that conveys a general philosophy, similar to the term REST (Representational State Transfer). Unobtrusive JavaScript doesn’t intermix JavaScript code in your page markup. Eg : Instead of using events like onclick and onsubmit, the unobtrusive JavaScript attaches to elements by their ID or class based on the HTML5 data- attributes.
What is the use of ViewModel in MVC?
ViewModel is a plain class with properties, which is used to bind it to strongly typed view. ViewModel can have the validation rules defined for its properties using data annotations.
What you mean by Routing in MVC?
Routing is a pattern matching mechanism of incoming requests to the URL patterns which are registered in route table. Class — “UrlRoutingModule” is used for the same process.
What are Actions in MVC?
Actions are the methods in Controller class which is responsible for returning the view or json data. Action will mainly have return type — “ActionResult” and it will be invoked from method — “InvokeAction()” called by controller.
What is Attribute Routing in MVC?
ASP.NET Web API supports this type routing. This is introduced in MVC5. In this type of routing, attributes are being used to define the routes. This type of routing gives more control over classic URI Routing. Attribute Routing can be defined at controller level or at Action level like –
[Route(“{action = TestCategoryList}”)] — Controller Level
[Route(“customers/{TestCategoryId:int:min(10)}”)] — Action Level
How to enable Attribute Routing?
Just add the method — “MapMvcAttributeRoutes()” to enable attribute routing as shown below
public static void RegistearRoutes(RouteCollection routes)
{
routes.IgnoareRoute(“{resource}.axd/{*pathInfo}”);
//enabling attribute routing
routes.MapMvcAttributeRoutes();
//convention-based routing
routes.MapRoute
(
name: “Default”,
url: “{controller}/{action}/{id}”,
defaults: new { controller = “Customer”, action = “GetCustomerList”, id = UrlParameter.Optional }
);
}
Explain JSON Binding?
JavaScript Object Notation (JSON) binding support started from MVC3 onwards via the new JsonValueProviderFactory, which allows the action methods to accept and model-bind data in JSON format. This is useful in Ajax scenarios like client templates and data binding that need to post data back to the server.