1. What is MVC (Model View Controller)? MVC is a design pattern used for developing web applications. It separates the application into three interconnected components: Model: Represents the application’s data and business logic. View: The user interface that displays data from the model to the user. Controller: Handles user input, manipulates the model, and updates the view accordingly. 2. What are the Advantages of MVC? Separation of Concerns: MVC separates the application into three components, making it easier to manage and test. Scalability: The separation allows for scalability since each component can be developed and tested independently. Reusability: Components of the application can be reused, which reduces code duplication. Maintainability: Changes in one part (like the view) do not affect the others, making the application easier to maintain. 3. Explain MVC Application Life Cycle Application Start: Initializes application configurations (e.g., routes, filters). Routing: The routing module maps the URL to a specific controller and action method. Controller Initialization: Instantiates the appropriate controller. Action Execution: The action method is executed, and any data is processed. Result Execution: The result (typically a view) is executed, which generates the HTML output. Response: The generated output is sent back to the client’s browser. 4. List Out Different Return Types of a Controller Action Method ViewResult (returns a view) PartialViewResult (returns a partial view) JsonResult (returns JSON-formatted data) RedirectResult (redirects to another action or URL) RedirectToRouteResult (redirects to a specified route) ContentResult (returns raw string content) FileResult (returns a file download) EmptyResult (returns no content) 5. What are the Filters in MVC? Filters are used to execute code before or after an action method runs. Types of filters: Authorization Filters: Handle authorization logic. Action Filters: Run before and after an action method is called. Result Filters: Run before and after the view result is executed. Exception Filters: Handle exceptions thrown by action methods. 6. What are Action Filters in MVC? Action Filters are a specific type of filter that allow logic to be run before and after an action method execution. Examples include logging, authentication checks, and caching. 7. Explain What is Routing in MVC? What are the Three Segments for Routing Important? Routing is the process of mapping a URL to a controller and action method. The three segments of a typical route are: Controller: Determines which controller to instantiate. Action: Determines which action method of the controller to call. Parameters: Any additional parameters required by the action method. 8. What is Route in MVC? What is Default Route in MVC? A Route is a URL pattern that is mapped to a controller action. The Default Route is typically defined in RouteConfig.cs and looks like this: 1 2 3 4 5 routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); 9. Difference Between TempData, ViewData, and ViewBag? TempData: Stores data temporarily during a redirect. It uses session storage and can only persist between two requests. ViewData: Stores data in key-value pairs, accessible only for the current request. ViewBag: Similar to ViewData but uses dynamic properties, making it easier to use. It is also request-scoped. 10. What is Partial View in MVC? A partial view is a reusable piece of a user interface that can be rendered inside another view. It is commonly used for components like headers, footers, and widgets. 11. Difference Between View and Partial View? View: A complete page that renders the full layout, including _Layout.cshtml. Partial View: A segment of a page that does not render the full layout. It is intended to be used within other views. 12. What are HTML Helpers in MVC? HTML Helpers are methods that generate HTML markup for use in views. Examples include Html.TextBoxFor(), Html.DropDownListFor(), etc. 13. Explain Attribute-Based Routing in MVC? Attribute-based routing allows routes to be defined directly on controller actions using attributes. It provides fine-grained control over routing. 1 2 [Route("products/details/{id:int}")] public ActionResult Details(int id) { ... } 14. What is TempData in MVC? TempData is used to pass data from one action to another. It stores data temporarily, and it uses the session state to persist data across requests. 15. What is Razor in MVC? Razor is a view engine that provides a streamlined syntax for embedding server-side code into HTML using C#. It uses @ as a marker for code. 16. Differences Between Razor and ASPX View Engine in MVC? Razor View Engine: Uses @ syntax. Cleaner and less verbose. Supports IntelliSense. ASPX View Engine: Uses <%= %> syntax. More verbose. No modern features like Razor. 17. Main Razor Syntax Rules Use @ to transition from HTML to C#. Use @{ ... } for inline C# code blocks. Use @model to specify the type of the model. Use @Html helpers to generate HTML markup. 18. Implement Forms Authentication in MVC Configure forms authentication in web.config. Use the [Authorize] attribute on controllers or actions. Redirect users to a login page if not authenticated. 19. Explain Areas in MVC Areas allow you to partition an MVC application into multiple sections. Each area can have its own controllers, views, and models. They are useful for organizing large applications into smaller modules. 20. Explain the Need of Display Mode in MVC Display modes allow the application to select different views based on the browser or device type. This is useful for creating mobile-optimized views. 21. Explain the Concept of MVC Scaffolding MVC scaffolding is a code generation tool that automatically creates CRUD operations and views for models, speeding up the development process. 22. What is Route Constraints in MVC? Route constraints restrict the type of data that parameters can accept in a route. Example: 1 2 3 4 5 6 routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, constraints: new { id = @"\d+" } // id must be numeric ); 23. What is Razor View Engine in MVC? The Razor View Engine is a templating engine that allows embedding C# code within HTML. It uses a .cshtml file extension. 24. What is Output Caching in MVC? Output caching stores the rendered HTML of a page so that subsequent requests can be served from the cache rather than regenerating the page. This improves performance. 25. What is Bundling and Minification in MVC? Bundling combines multiple CSS or JavaScript files into a single file. Minification removes unnecessary characters (like whitespace) from code to reduce file size. Both techniques improve page load time. 26. What is Validation Summary in MVC? The ValidationSummary helper displays a summary of all validation errors on the page. It collects errors from all fields and displays them at the top of the form. 27. What is Database First Approach in MVC using Entity Framework? The Database First approach generates model classes and a DbContext from an existing database schema. It is useful when you have a pre-existing database that you want to use. 28. What are the Folders in MVC Application Solutions? Controllers: Contains controller classes. Models: Contains model classes. Views: Contains view files (.cshtml). wwwroot: Stores static files like images, CSS, and JavaScript. Areas: Contains sub-folders for modular parts of the application. 29. Difference Between MVC and Web Forms MVC: Uses the MVC pattern (Model-View-Controller). Promotes separation of concerns. Does not use ViewState. Web Forms: Follows an event-driven programming model.
...