#

Questions & Answers

ASP.NET MVC Questions & Answers

Provides Latest and Useful Interview Q & A on ASP.NET technology

1. Explain what is Model-View-Controller?

MVC is a software architecture pattern for developing web application. It is handled by three objects Model-View-Controller.

2. Mention what does Model-View-Controller represent in an MVC application?

In an MVC model

3.Explain in which assembly is the MVC framework is defined?

The MVC framework is defined in System.Web.Mvc

4. Different types of data dictionary in mvc.


5.Mention what is the difference between adding routes, to a webform application and an MVC application?

To add routes to a webform application, we can use MapPageRoute() method of the RouteCollection class, where adding routes to an MVC application, you can use MapRoute() method.

6. Mention what are the two ways to add constraints to a route?

The two methods to add constraints to a route is


7. Mention what is the advantages of MVC?


8. Mention what "beforFilter()","beforeRender" and "afterFilter" functions do in Controller?


9. Explain the role of components Presentation, Abstraction and Control in MVC?

10. Mention the advantages and disadvantages of MVC model?

Advantages


Disadvantages


11. Explain the role of "ActionFilters" in MVC?

In MVC " ActionFilters" help you to execute logic while MVC action is executed or its executing.

12. Explain what are the steps for the execution of an MVC project?

The steps for the execution of an MVC project includes


13. Explain what is routing? What are the three segments for routing is important?

Routing helps you to decide a URL structure and map the URL with the Controller.

The three segments that are important for routing is


14. Explain how routing is done in MVC pattern?

There is a group of routes called the RouteCollection, which consists of registered routes in the application. The RegisterRoutes method records the routes in this collection. A route defines a URL pattern and a handler to use if the request matches the pattern. The first parameter to the MapRoute method is the name of the route. The second parameter will be the pattern to which the URL matches. The third parameter might be the default values for the placeholders if they are not determined.

15. Explain using hyperlink how you can navigate from one view to other view?

By using "ActionLink" method as shown in the below code. The below code will make a simple URL which help to navigate to the "Home" controller and invoke the "GotoHome" action.

@Html.ActionLink("Home", "Gotohome")

16. Mention how can maintain session in MVC?

Session can be maintained in MVC by three ways tempdata, viewdata, and viewbag.

17. Mention what is the difference between Temp data, View, and View Bag?


18. What is partial view in MVC?

Partial view in MVC renders a portion of view content. It is helpful in reducing code duplication. In simple terms, partial view allows to render a view within the parent view.

19. Explain how you can implement Ajax in MVC?

In MVC, Ajax can be implemented in two ways


20.Mention what is the difference between "ActionResult" and "ViewResult" ?

"ActionResult" is an abstract class while "ViewResult" is derived from "AbstractResult" class. "ActionResult" has a number of derived classes like "JsonResult", "FileStreamResult" and "ViewResult" .

"ActionResult" is best if you are deriving different types of view dynamically.

21. Explain how you can send the result back in JSON format in MVC?

In order to send the result back in JSON format in MVC, you can use "JSONRESULT" class.

22. Explain what is the difference between View and Partial View?

View Partial View

23. List out the types of result in MVC?

In MVC, there are twelve types of results in MVC where "ActionResult" class is the main class while the 11 are their sub-types


24. What is the order of the filters that get executed, if multiple filters are implemented?

The filter order would be like:


25. What are the file extensions for razor views?

For razor views, the file extensions are

26. How may Ajax be used in MVC?

There are two techniques to integrate Ajax with MVC.


27. What is scaffolding?

Scaffolding is a code generation framework mostly used for ASP.NET web applications.

28. What is Razor in ASP.NET MVC?

Razor is the new view-engine introduced by MVC3, which acts as pluggable modules and applies different template syntax options.

29. What is the default route in MVC?

A default route adds a generic route that utilizes the URL convention to break the URL for a given request in three segments.

29. What is the difference between GET and POST action types?

The GET action type requests data from particular resources, while the POST action type submits data that needs to be processed to a specific resource.

29. How do we implement validation in the MVC?

We can implement validation in the MVC application with well-defined validators in the System.ComponentModel.DataAnnotations namespace.

30. What are NonAction methods in MVC?

In MVC all public methods have been treated as Actions. So if you are creating a method and if you do not want to use it as an action method then the method has to be decorated with NonAction attribute

31. 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.

32. What is a cookie ?

Cookies are small text files information which is stored in the end users computer.

33. What does Keep do in tempdata ?

Keep method persist the data for the next request.

34. Explain Peek in tempdata ?

Peek = Keep + Read. It will read as well as keep the data.

35. Is tempdata private to a user ?

Yes , Tempdata is private to a user.

35. What is WebAPI ?

Web API controller delivers data and services easily by using HTTP REST services.

36. Explain some of the rules of Razor syntax

Here are some of the rules of Razor syntax:

37. What are the main differences between ASP.NET Web Forms and ASP.NET MVC?

ASP.NET Web Forms is a framework that follows a different pattern known as Web Forms, while ASP.NET MVC follows the MVC pattern. In Web Forms, the UI controls and code-behind files are tightly coupled, whereas in MVC, the UI is separate from the controller logic. MVC provides more control over the HTML output, supports clean URLs, and promotes testability through its separation of concerns.