Top 40 MVC Interview Questions and Answers | Most Frequently Asked ASP.NET MVC Questions | Edureka

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey everyone this is Neha from a do Rekha and I welcome you all to Eddy Rica's YouTube channel so this session is all about NBC interview questions so in this video I have collected the most frequently asked questions which are collected after consulting with top industry experts in the field of design patterns asp.net and Spring Framework if you wish to brush up with the MVC basics which I recommend you to do before going ahead with the interview questions I suggest you to take a look at the videos on MVC tutorial in our YouTube playlist so in case you come across some other questions during your interviews or you have some queries that might be helpful for others as well so do share them in the comment section and we will help you with the solution so well let's have a look at the agenda for the session so in this video I will be covering the top 40 questions which comprise of the basic interview questions for our beginners and intermediate interview questions for mid-level experienced people and advanced interview questions for experienced professional as well so it is being divided into three different sections that is basic for beginner level intermediate interview questions and advanced level MVC interview questions as well so now let's begin with the very first question for beginners so the first question on the list is what does MVC MVC is an abbreviation for Model View and controller the MVC architectural pattern separates an application into three components at this Model View and controller in this pattern the model represents the shape of the data and business logic it maintains and preserve the data of the application and model objects retrieve and store the model state in a database now talking about the view it is basically an technically a user interface the view segments displays the data using model to the user and also enables them to modify the data now talking about the last bounine that is a controller it is the part which handles user requests so this is all about the Model View and controller and how these functions the next question on the list is mentioned what does Model View and controller represents in an MVC application talking about the model it represents the application data domain as I have already mentioned before it is the application business logic and is contained within the model and is responsible for maintaining the data and view represents a user interface with which the end users communicate in short all the user interface logic is contained within the view and now talking about the controller it answers to the users actions based on the user actions the respective controller responds within the model and choose a view to render that display the user interface the user input logic is contained within the controller so these are the functionalities of Model View and controller and you can see in this picture the next question that we have on the list is list out a few different return types of a controller action method as like every other component has its own return type even controller action also has its return types so I am going to name a few of them first view result next JavaScript result read direct result JSON result and content result so these are the different return types of a controller action method now let's move ahead and take a look at the next question the next question that we have is what are the advantages of MVC and this we have a wide range of advantages now let me name a few of the advantages and tell you how these actually benefit the model view controller pattern the first one is multiple view support because of the separation of the model from the view the user interface can display multiple views of the same data and at the same time next change in accomodation user interfaces tend to change more frequently than business rule the next advantage is SOC at the separation of concerns separation of concerns is one of the core advantages of asp.net MVC and the MVC framework provides a clean separation of user interface business logic model or data next more control this again comes in respect to asp.net MVC framework and that provides more control over HTML Javascript and CSS than the traditional web forms next is testability the framework provides better testability of the web application and good support for the test-driven development - the next one is lightweight MVC framework doesn't use viewstate and that reduces the bandwidth of the request to an extent so these are the various advantages of MVC and that's a reason MVC is one of the most popular pattern that is widely being used in case of JavaScript asp.net and spring as well next question is explain the role of components at this presentation abstraction and control in MVC so presentation is basically the usual representation of a specific abstraction within the application talking about the abstraction it is the business domain functionality within the application and control is a component that keeps the consistency between the abstraction within the system and their presentation to the user it is also used to communicate with other controls within the system next question is how to maintain session in MVC so it is very simple because session can be maintained in MVC by three ways that the stem data view data and view back so moving further in the session you will also understand what is view data what is view bag and what is the difference between them and what is them data as well next is what does MVC application lifecycle so now let me tell you water this so any web application has two main execution steps first understanding the request and next depending on the type of the request you have to send out an appropriate response and MVC application lifecycle has two main phases first creating the request object and second sending the response to the browser so if you have to create the object that is a request object it basically includes four main steps first you have to fill the route then fetch the route then you have to create the request context and then the controller instance will be created after this you have to send the response back very simple the next question is what does the MVC pattern defined with the three logical layers the Embassy model web applications with three different layers that is the business layer which is a model logic the display layer which is the view logic and the input control which implies a controller logic so the model is the part of the application which only handles a logic for the application data regularly the model object retrieves the data from a database and the view is a part of the application which takes care of the display of the data most often the views are created from the model data although there are other more complicated methods of creating views and the controller as the name implies as a part of the application that handles the user infraction so these are the three different logical layers that MVC model defines the web applications talking about the next question it is what a spring MVC it is a Java framework which is used to build the web applications and that also follows model view controller design pattern not just that it also implements all the basic features of the core spring framework like inversion of control dependency injection exception spring MVC provides a dignified solution to use MVC in the spring framework with the help of a dispatcher servlet in this case dispatcher servlet is a class that receives incoming requests and maps it to the right resource such as controller model and views so that is all about what a spring MVC next question what does asp.net MVC this is also a web application framework it is lightweight and highly testable framework MVC separates an application into three components again that is Model View and controller is just that MBC is being used in a different ways for a spring and asp.net next question is what does MVC routing so this comes under asp.net only and the URLs in the asp.net MVC are mapped with the action methods and controller instead of physical files in a system in order to accurately map the action methods and the controllers to URLs the routing ancient forms appropriate routes using this the controller can handle the specific requests so first there are requests as being sent to the routing engines and then across the routes is sent to the controller where the controller can handle the specific requests I hope you got this next what are the filters sometimes what happens we want to execute some logic either before the execution of the action method or after the execution and such kind of scenarios we can use action filters and filters define the logic which is executed before or after the execution of the action method action filters are attributes which we can apply to the action methods so we have some types of filters for example you have authorization filters that implements a authorization filter and you have action filter you have result and exception filter as well and these are being used for separate implementations for action for I result for I exception etcetera next what is a partial view in MVC a partial view is a chunk of HTML that can be safely inserted into an existing Dom most commonly partial views are used to componentize RAZR views and make them easier to build an update it can also be returned directly from controller methods in this case the browser still receives the text or HTML content but not necessarily HTML content that makes up an entire page as a result if the URLs that returns a partial view is directly invoke from an address bar of a browser an incomplete page may be displayed this may be something like a page that misses title script and style sheets next question is can you explain the page lifecycle of MVC basically a page lifecycle involves five different stages first one is app initialization after that you have to go with the routing after routing is done you have to instantiate and execute the controller and once you've instant she ate the controller you have to locate and invoke the controller action and then instantiate and you have to render the view so these are the various steps that is involved starting from the app initialization to rendering the view and page lifecycle of MVC next question is what is the use of view model in MVC view model is a plain class with properties which is used to bind it to a strongly typed view it can have the validation rules that is defined for its properties using the data annotation so this is the main use of view model in MVC so these are some of the questions for beginners now I will move further and tell you some of the intermediate level interview questions the next question on the list is what does database first approach in MVC using the entity framework database first approach is an alternative or substitutes to the code first and model first approaches to the data entity model the entity data model creates model codes from the database in the project and that class behaves as a link between the database and controller so the approaches that is being used to connect to a database are database first model first and code first next what do you mean by MVC scaffolding scaffolding is a code generation framework for asp.net web applications Visual Studio includes pre-installed code generators for MVC and Web API projects you can ask a fowling to your projects when you want to quickly add the code that interacts with the data models using scaffolding it will reduce an amount of time that is used to develop the standard data operations in your project it consists of a page templates entity page templates field page templates and filter templates as well these templates are call scaffold templates and they allow you to quickly build a functional data-driven website the next question is explain the concept of raiser in asp.net MVC asp.net MVC has always supported the concept of view engines which are the pluggable modules that implement different template syntax options the default view engine for asp.net MVC uses the same dot aspx and dot asp CX master file templates as asp.net webforms other popular asp.net MVC view engines are sparked and NH AML and racer as a new engine which was introduced by MVC version 3 next question is explain the concept of default route in MVC the default asp.net MVC project templates add a generic route that uses this URL convention to break the URL for a given request into three named segments suckers controller action and ID and you have to write it in this pattern and this route pattern is registered via a call to the Map Reduce extension method of route collection the next question on the list is what is get and post action pipes ket is used to request data from a specified resource with all the get requests we can pass the URL which is compulsory however it can take up the full length overloads next post action type the post is used to submit the data to be processed to a specific resource with all the post requests we can pass the URL and the data which is essential however it can also take up many overloads as well next how does view data differ from view back in MVC so basically view data is used to pass the data from a controller to a view and view PAC is also used to pass the data from a controller back to the respective view next view data is available for the current request only view bag is also available for the current request next point view data requires typecasting for complex data type and checks for null values to avoid the error but view bag on the other hand doesn't require typecasting for the complex data type next if the redirection occurs then it value becomes null in case of field data same goes with view bag as well if the redirection of course then even the value becomes null so these are some of the similarities and the differences between view data and view bag in modal view controller next question is mention the benefits of area in MVC it's easy for unit testing it is easy to integrate with other areas that is created by another it allows us to organize Model View and controller into separate functional sections of the application such as administration building customer support and many more so these are some of the benefits of area and MVC next question is which filters are executed in the end so basically in the end exception filters are executed by because first you have to authorize a request so authorization filter will be executed first and then the action filter and then you have to implement the result filter and finally the exception filter so if there are any exceptions or errors and it will be handled and that is the reason it is executed in the end next what are the two ways of adding constraints to a rule the two methods of adding a constraint to a route is by using regular expression and by using an object that implements a route constraint interface the next question on the list is how to implement validation in MVC we can easily implement validation in MVC by using the validators that are defined in the system component model data annotations namespace so there are different types of validators like required data type range and string length so mention the two instances where routing is not implemented or required the two instances where routing is not required or implemented are when a physical file is found that matches the URL pattern and when a routing is disabled for a URL pattern so these are the two instances where routing is not required so how can you implement our Jackson MVC so basically it can be implemented in two ways by using Ajax libraries and by using jQuery if you wish to know what is jQuery you can check out the jQuery tutorial in our YouTube playlist next what is the use of keep and peek in temp data one stem data is read in the current request it is not available in the subsequent request if you want temp data to be read and also available in the subsequent request then after reading we need to call the keep method so you can see in the below pour so first what I am doing and using them data and invoking my data so once I read this in the current request it is not available for the next subsequent request so if I want to keep it I should use the keep method and then write it in this format and the more shortcut way of achieving the same is by using peak this functions helps to read as well as advises MBC to maintain temp data for the subsequent requests so I have created an object for string and just using peak and sending it to string so this is how I can use it next question is what is Web API HTTP is the most commonly used protocol since many years the browser was the most preferred client by which beacons data exposed over HTTP but as years passed by client variety started spreading out we have demanded to consume data on Esther DB from clients like mobile JavaScript Windows application etc for satisfying the broad range of clients rest was the proposed approach Web API is a technology by which you can expose the data over HTTP following rest principles next how can we detect that an MVC controller is called by a get or post to dip deck if a call in the controller as a get action or a post action we can use the request dot HTTP method property as shown in this code so first there's a method called action results some action then in if condition I'm using request dot HTTP is equal to post if this is the case then it will return the view of some page that is whatever the action is else it will return the view or the display of some other page by this you can understand whether the request is a get or a post now let's move further and look at some of the advanced NBC interview questions the first question in Advanced section is what are the main raisers and tax rules so the first point is raiser code blocks are enclosed in add symbol and followed by the flower braces and the inline expressions that as the variables and functions also should start with add symbol and the course statement should end with a semicolon variables are declared with the Val cuboid and strings are enclosed with quotation marks c-sharp code the scale sensitive and c-sharp file extension should have dot CS HTML so these are some of the major syntax rules for raiser next how do you implement forms authentication in MVC authentication is giving access to the user for a specific service by verifying his or her identity by using his or her credentials like username password or email and pass it assures that the correct user is authenticated or logged in for specific service and the right service has been provided to the specific user based on the rule next what do you mean by render body and render page in MVC render body is like content placeholder and web forms this will exist in layout page and it will render the child pages or views layout page will have only a one render body method and render page also exists in layout page and multiple render page can be used or can be present in the layout pages so what are non action methods and MVC in MVC all the public methods have been treated as actions so if you are creating a method and do not wish to use it as an action method then the method has to be decorated with the non action attribute so here you have a method called test method and you can write any method logic and if you don't want to use the action method then you have to use the non action as shown here very simple right next how to perform exception handling in MVC in the controller you can override the on exception event and set the result of the view name which you want to invoke when an error occurs so you can see in this court that we have set the result to a view that is named as error okay and you have also set the exception so that it can be displayed inside the view so there is a class called home controller and I'm overriding the on exception with the filter context that is exception context and then defining the exception IX is equal to filter context at exception and then I am renaming the handled exception of filter context to true then inside I am naming the view to error if there is any view data then it will display and if there is any error in the result then it will be displayed as error so this is how you need to perform exception handling in MBC so which is a better fit razor or aspx as for the Microsoft razor is more preferred because it is lightweight and has simple syntaxes that is a reason razor is more preferred over aspx next what are the chord blocks in MVC unlike code expressions that are evaluated and sent to the response that is the blocks of code that are executed and this is useful for declaring variables which we may require to be used in a later purpose this is how a chord blocks can be written using add symbol and followed by a flower brace and I have declared a variable for integer and string and then again close the flower brace so this is nothing but a code block in a view next I use HTML at partial in MVC this method is used to render the specified partial view as an HTML string this method does not depend on any action methods so we can use it like first add symbol HTML got partial and inside you can pass tests partial view next question is what is a glimpse glimpse is a new get packages which help in finding performance debugging and diagnostic information it can also help you get the information about the timelines model bindings routes environment etc now the last question is how to navigate from one view to one another using a hyperlink by using the action link method you can navigate so take a look at the code which will help you create a simple URL which helps you navigate the home controller and invoke the go to home action so this is a code syntax where I have used HTML of action link the home controller and the navigation page that is a go to home and followed by this so this is how you can navigate from one view to another using a hyperlink with this we come to an end of this video on MBC interview questions I hoped it helped in adding up your knowledge and I wish you all the best for your interview if you have any queries you can comment in the comment section below and we will reply back to you at the earliest thank you for attending this session have a nice day I hope you have enjoyed listening to this video please be kind enough to like it and you can comment any of your doubts and queries and we will reply them at the earliest do look out for more videos in our playlist and subscribe to any Rekha channel to learn more happy learning
Info
Channel: edureka!
Views: 130,894
Rating: 4.7693167 out of 5
Keywords: yt:cc=on, mvc interview questions, mvc interview questions 4 years experience, mvc interview questions and answers, mvc interview questions and answers for beginners, mvc interview questions and answers for experienced, mvc interview questions and answers for freshers, mvc interview questions c#, mvc interview questions experience, mvc interview questions experienced, edureka, asp.net mvc interview questions and answers, mvc questions for interview, asp.net mvc preparation
Id: Mlkgr6SOkUM
Channel Id: undefined
Length: 27min 13sec (1633 seconds)
Published: Sun Sep 08 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.