1. What is MVC?
    MVC (Model-View-Controller) is a software design pattern that separates an application into three interconnected components: Model, View, and Controller. This separation helps organize code, manage complexity, and improve scalability, maintainability, and testability.

  2. How do the Model, View, and Controller function?

    • Model: Manages the data, logic, and rules of the application. It represents the business data and operations on that data.
    • View: Represents the presentation layer. It displays data from the model to the user and sends user commands to the controller.
    • Controller: Acts as an intermediary between the Model and the View. It handles user input, updates the model, and decides which view to display.
  3. What are the different return types of a controller action method?

    • ViewResult: Renders a view.
    • JsonResult: Returns JSON-formatted data.
    • RedirectResult: Redirects to another action method or URL.
    • PartialViewResult: Renders a partial view.
    • ContentResult: Returns raw content (e.g., plain text or HTML).
    • FileResult: Returns a file to the client.
    • EmptyResult: Represents no response.
    • HttpNotFoundResult: Represents a 404 error.
  4. What are the advantages of MVC?

    • Separation of Concerns: Clear division between business logic, UI, and input logic.
    • Scalability: Easier to scale due to modular components.
    • Testability: Isolates logic, making unit testing more straightforward.
    • Maintainability: Changes in one part (e.g., UI) do not affect other parts (e.g., business logic).
    • SEO-Friendly URLs: Enables cleaner, more readable, and SEO-friendly URLs.
  5. Can you explain the advantages of MVC in detail?

    • Modularity: Each component (Model, View, Controller) can be developed, tested, and maintained independently.
    • Flexibility: The use of interfaces and abstract classes makes it easier to swap out implementations.
    • Reusability: Models can be reused across different views and controllers, reducing code duplication.
    • Improved UI and business logic separation: Changes in UI can be made with minimal impact on the business logic.
    • Rapid Development: Features like scaffolding in ASP.NET MVC speed up development by automatically generating basic CRUD operations.
  6. What are the roles of Presentation, Abstraction, and Control?

    • Presentation (View): Displays the data and the UI components.
    • Abstraction (Model): Encapsulates the data and the business rules.
    • Control (Controller): Handles user input and manages the flow of data between the Model and View.
  7. Can we maintain a session in MVC?
    Yes, MVC provides support for session management similar to traditional ASP.NET applications. Sessions can be managed using Session objects, cookies, and other state management techniques.

  8. What is the life cycle of an MVC Application?

    • Application Start: Application starts with Global.asax, initializing routes and dependencies.
    • Routing: Incoming requests are matched to routes defined in RouteConfig.
    • Controller Initialization: Appropriate controller is instantiated.
    • Action Execution: Controller action method is invoked.
    • Result Execution: Action method returns a result (view, JSON, etc.), which is processed.
    • View Rendering: The view is rendered and returned to the client.
  9. Define the Model logic.
    The Model represents the application’s data and business rules. It directly manages the data, logic, and rules of the application, typically by interacting with a database and providing data to the view.

  10. Define the View logic.
    The View is responsible for displaying the data provided by the Model to the user. It represents the presentation layer of the MVC pattern and uses Razor syntax to bind and present data dynamically.

  11. Define the Controller logic.
    The Controller handles user input and requests, manipulates the Model, and selects the View to display. It acts as a coordinator between the Model and the View.

  12. Define ASP.NET MVC.
    ASP.NET MVC is a web application framework developed by Microsoft that implements the MVC (Model-View-Controller) design pattern. It provides a structured way to develop web applications by separating concerns, allowing for more maintainable, scalable, and testable code.

  13. What is MVC Routing?
    Routing in MVC is a pattern-matching system used to define how URL requests map to specific controller actions. Routes are configured in the RouteConfig file and determine the path of URLs to corresponding controllers and actions.

  14. Define filters.
    Filters in MVC are used to run custom code before or after certain stages of request processing (e.g., before/after an action method runs). They are used for tasks such as authorization, error handling, caching, and logging.

  15. What are the different kinds of MVC action filters?

    • Authorization Filters: Handle authentication and authorization logic.
    • Action Filters: Run code before and after executing action methods.
    • Result Filters: Run code before and after the result of the action method is processed.
    • Exception Filters: Handle exceptions thrown during the execution of an action method.
  16. Define Partial View and Razor View.

    • Partial View: A reusable view that represents a portion of the web page. It is used to encapsulate a piece of UI that can be reused across multiple views.
    • Razor View: A view that uses the Razor syntax to embed server-side code into HTML. It has a .cshtml or .vbhtml file extension and is used for dynamically generating content.
  17. What is the page life cycle of MVC?

    • Request Routing: Request matches a route defined in the RouteConfig.
    • Controller Instantiation: Controller is instantiated.
    • Action Execution: Action method is invoked.
    • Action Filters: Action filters execute.
    • Action Result Execution: Result (e.g., view) is generated.
    • View Engine: View is rendered.
    • Response: The final output is sent back to the client.
  18. What is the use of ViewModel in MVC?
    A ViewModel is a model specifically created to pass data from the controller to the view. It is used to encapsulate multiple pieces of data and logic required by the view and provides a strongly typed way to interact with the data.

  19. What is the database-first approach using the Entity Framework?
    The database-first approach involves creating a model in the Entity Framework based on an existing database schema. It automatically generates classes representing database tables, allowing interaction with the database using LINQ.

  20. What are different approaches to connect the database with the application?

    • Database First: Generate models based on an existing database schema.
    • Code First: Define models using code, and the database schema is generated automatically.
    • Model First: Design a model in the Entity Framework Designer, which generates the database schema.
  21. What is scaffolding?
    Scaffolding is a code generation technique used in ASP.NET MVC to automatically create CRUD (Create, Read, Update, Delete) operations and views based on the model class definitions.

  22. How are Visual Studio and MVC related?
    Visual Studio is an integrated development environment (IDE) that provides built-in templates, tools, and features to create and develop MVC applications efficiently.

  23. What are the different kinds of scaffold templates and their uses?

    • Empty: Generates a minimal project structure with necessary folders.
    • Create: Generates a form to create a new entity.
    • Edit: Generates a form to edit an existing entity.
    • Delete: Generates a confirmation page for deleting an entity.
    • Details: Generates a view to display details of an entity.
    • List: Generates a view to list multiple entities.
  24. What is Razor in ASP.NET MVC?
    Razor is a lightweight view engine that allows embedding C# code directly into HTML. It provides a concise syntax using @ to combine code and markup, facilitating dynamic content generation.

  25. What is the default route in MVC?
    The default route is typically defined as {controller}/{action}/{id}, which maps to a controller’s action method. For example, Home/Index/5 would call the Index action method on the HomeController with the parameter id=5.

  26. How is the route pattern registered in this case?
    Route patterns are registered in the RouteConfig class, typically located in the App_Start folder, using the RouteCollection object and its MapRoute method.

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

    • GET: Requests data from a server. Data is appended in the URL, which makes it less secure.
    • POST: Sends data to the server for processing. Data is included in the body of the request, making it more secure for transmitting sensitive information.

What are the differences between View data and View Bag?
- ViewData: A dictionary object used to pass data from the controller to the view. It requires type casting and checks for null values. - ViewBag: A dynamic property that provides a more flexible way to pass data from the controller to the view without needing type casting.

  1. What are the benefits of the Area in MVC?

    • Modularity: Organizes large applications into smaller sections.
    • Reusability: Makes it easier to reuse and maintain code.
    • Routing: Allows defining different routes within different areas.
    • Isolation: Provides separation between different functionalities.
  2. What are the steps to create the request object?

    • Routing: The incoming request is matched against the routes.
    • Controller Selection: The appropriate controller is selected based on the route.
    • Action Method Selection: The action method is selected and called.
    • Result Execution: The result is executed and returned to the client.
  3. Define the three logical layers of the MVC Pattern.

    • Model: Handles data and business logic.
    • View: Displays the data to the user.
    • Controller: Handles user input and manages interactions between the Model and View.
  4. How do we implement validation in the MVC?

    • Using Data Annotations: Applying attributes to model properties (e.g., [Required], [StringLength]).
    • Using ModelState: Checking the ModelState.IsValid property to verify if the submitted data meets the validation rules.
    • Using Custom Validation: Implementing custom validation logic either in the model or using a separate validation service.
  5. What are the different types of validators?

    • Required: Ensures a field is not left empty.
    • StringLength: Validates the length of a string.
    • Range: Ensures a numeric value falls within a specified range.
    • RegularExpression: Validates input using a regular expression.
    • Compare: Compares the value of one property with another.
  6. Are there any circumstances where routing is not required or cannot be implemented?

    • Static Files: Direct access to static files (e.g., images, CSS) doesn’t require routing.
    • Web API: If using dedicated APIs that don’t follow MVC routes.
    • Single Page Applications (SPA): Routing is typically handled client-side, not via MVC.
  7. How can Ajax be implemented?
    Ajax can be implemented in MVC using jQuery or vanilla JavaScript by making asynchronous HTTP requests to the server. This allows partial page updates without full-page reloads.

  8. What was the need to introduce WebAPI technology?
    WebAPI was introduced to provide a framework for building RESTful services that can be consumed by a wide variety of clients (e.g., browsers, mobile apps). It is lightweight and ideal for HTTP-based services.

  9. What are the main Razor Syntax Rules?

    • Use @ to transition from HTML to C# code.
    • Use @{ ... } for inline C# code blocks.
    • Use @model to specify the type of model passed to the view.
    • Use @Html helpers for rendering HTML elements and binding data.
  10. What is Forms Authentication?
    Forms Authentication is an authentication mechanism for validating user credentials in ASP.NET applications. It uses a form to log in users and issues a cookie to track authenticated users.

  11. Why do we need Forms Authentication?
    It provides a simple and effective way to manage user authentication, ensuring that only authenticated users can access certain parts of the application.

  12. What is the difference between RenderBody and RenderPage?

    • RenderBody: Placeholder in the layout view for rendering the content of child views.
    • RenderPage: Renders a partial view within the main view.
  13. What are non-action methods?
    Non-action methods are methods within a controller that cannot be directly invoked via URL routing. They are typically marked with the [NonAction] attribute.

  14. Which is preferred: Razor or ASPX?
    Razor is generally preferred due to its cleaner syntax, better integration with C#, and improved performance compared to ASPX.

  15. What is Glimpse?
    Glimpse is a diagnostics tool for ASP.NET applications, providing insights into what’s happening on the server side, including execution times, routes, and more.

  16. What can help in navigating from one view to another using a hyperlink?
    HTML helpers like @Html.ActionLink can generate links that navigate from one view to another by specifying the controller and action.

  17. Which filters can you execute at the end?

    • Result Filters: These can be executed after the action result has been executed.
    • Exception Filters: Executed if there is an exception in the action method or action result.
  18. What are the possible constraints to a route?
    Constraints can be applied using regular expressions or specific types, such as integer constraints ({id:int}), length constraints, or custom constraints.

  19. What are some other benefits of using MVC?

    • SEO-Friendly URLs: Easier to optimize for search engines.
    • Loose Coupling: Easier to replace or update components without affecting others.
    • Increased Control: More control over the HTML, JavaScript, and CSS, improving client-side performance and user experience.
  20. Is it possible to automate manual testing and write a unit test?
    Yes, MVC architecture’s separation of concerns makes it easier to write unit tests. Controllers, models, and routes can be independently tested using frameworks like NUnit, xUnit, or MSTest, and tools like Selenium for automated UI testing.