What does MVC stand for in ASP.NET?
Model-View-Controller
Which component of MVC handles the data logic and business rules?
Model
Which component of MVC is responsible for rendering the user interface?
View
In ASP.NET MVC, which component is responsible for handling user input and updating the Model?
Controller
Which file type is commonly used for Views in ASP.NET MVC?
.cshtml
In MVC, where is the routing configuration typically found?
RouteConfig.cs
How does ASP.NET MVC handle requests from the client?
By mapping URL patterns to controllers and actions
What is the default convention for the naming of controllers in ASP.NET MVC?
Controller suffix (e.g., HomeController)
Which attribute in ASP.NET MVC is used to denote a method as an action method?
[HttpGet] or [HttpPost]
How can you pass data from a Controller to a View in ASP.NET MVC?
Using ViewBag, ViewData, or a strongly-typed Model
What is the primary purpose of the ViewBag
in ASP.NET MVC?
To dynamically pass data from the Controller to the View
What is the difference between ViewBag
and ViewData
?
ViewBag
uses dynamic properties, while ViewData
uses a dictionary
In ASP.NET MVC, how can you create a strongly-typed view?
By passing a Model object to the View and using @model
directive
What is the role of the RouteConfig
class in MVC?
To define URL routing patterns for the application
Which method of the RouteConfig
class is used to configure routes?
RegisterRoutes
In ASP.NET MVC, what is the purpose of the ActionResult
class?
To represent the result of an action method and render appropriate content
What is the use of the PartialView
method in ASP.NET MVC?
To render a partial view within a parent view
How can you return a JSON result from an action method in ASP.NET MVC?
By using Json()
method of Controller
What does the HtmlHelper
class provide in ASP.NET MVC?
Helper methods for rendering HTML elements in Views
How can you implement form validation in ASP.NET MVC?
By using data annotations in the Model and HtmlHelper
methods in Views
What is the default value of the TempData
dictionary?
It is a dictionary used to pass data from one request to another and is cleared after the next request
In MVC, what is the role of ModelState
?
To store state information and validation errors related to the Model
What is a ViewModel
in ASP.NET MVC?
A class that contains data specific to a View, often combining multiple Models
How can you customize error handling in ASP.NET MVC?
By using custom error pages, HandleError
attribute, or global error handling in Global.asax
What is the purpose of Areas
in ASP.NET MVC?
To partition a large application into smaller, manageable sections
Which file is used to configure global settings and routes in ASP.NET MVC?
Global.asax
What is the purpose of the ControllerBase
class in MVC?
To provide basic functionalities required for all controllers
Which attribute is used to restrict access to an action method based on user roles?
[Authorize]
What is the function of IActionResult
interface in ASP.NET MVC?
To define the result type of an action method
How can you implement dependency injection in ASP.NET MVC?
By configuring services in Startup.cs
and using constructor injection in controllers
What is RedirectToAction
used for in ASP.NET MVC?
To redirect the user to a different action method
What are TempData
and Session
used for in ASP.NET MVC?
TempData
is used for short-lived data between requests, while Session
is used for longer-lived user-specific data
How can you create a custom ActionFilter
in ASP.NET MVC?
By inheriting from ActionFilterAttribute
and overriding its methods
What is the purpose of the ModelBinder
in ASP.NET MVC?
To bind request data to model properties
How can you use Html.Partial
in a View?
To render a partial view from within another view
What is the difference between Html.RenderPartial
and Html.Partial
?
Html.RenderPartial
writes directly to the response stream, while Html.Partial
returns a string
How do you implement authentication in ASP.NET MVC?
By using the Authentication
middleware or custom authentication logic
What is the role of ViewModel
in data-binding?
To aggregate data from multiple models for use in a View
How can you use @Html.Action
in a View?
To invoke a child action and render its result inline within the parent view
How do you configure routing in ASP.NET MVC?
By defining routes in RouteConfig.cs
or Startup.cs
What does the ActionName
attribute do in ASP.NET MVC?
It allows specifying a different name for an action method
What is the purpose of ActionFilters
in MVC?
To add pre-processing and post-processing logic to action methods
How can you create a new instance of a ViewModel in an action method?
By initializing the ViewModel object and passing it to the View
What is the purpose of the HttpPost
attribute in MVC?
To specify that an action method should respond to HTTP POST requests
How can you use Html.BeginForm
in a View?
To create an HTML form that posts data to a specified action method
What is the role of HtmlHelper
extension methods?
To provide reusable helper methods for generating HTML in Views
What is ContentResult
used for in an MVC action method?
To return plain text content as a result
How do you use ViewData
in a View?
By accessing it using key-value pairs
What is the purpose of ModelState.IsValid
?
To check whether the model passed validation rules
How can you implement a custom route in ASP.NET MVC?
By defining it in RouteConfig.cs
with specific URL patterns and constraints
What does Html.EditorFor
do in ASP.NET MVC?
Generates HTML markup for editing a property of the model
How can you override the default route constraints in ASP.NET MVC?
By specifying custom constraints in the route configuration
What is ViewBag
typically used for?
To pass dynamic data from the Controller to the View
How can you make a View strongly-typed to a specific Model?
By declaring the model type at the top of the View with @model
What does RedirectToRoute
method do in an action method?
Redirects the user to a different route based on route values
How do you use Html.ActionLink
in a View?
To generate a hyperlink that points to a specific action method
What is PartialViewResult
used for in ASP.NET MVC?
To return a partial view result from an action method
What is the use of ActionFilterAttribute
?
To create custom logic that can be applied to action methods before or after execution
What does ContentResult
return in an MVC action method?
Plain text or HTML content directly to the response
What is the main difference between Redirect
and RedirectToAction
?
Redirect
sends a raw URL to the client, while RedirectToAction
redirects to a specified action method
How do you handle form submissions in ASP.NET MVC?
By creating action methods that accept form data and process it accordingly
How can you use Html.DisplayFor
in a View?
To render HTML for displaying a model property
What is ViewData
typically used for?
To pass data from the Controller to the View in the form of a dictionary
What is the role of the BaseController
class in MVC applications?
To provide common functionality for all controllers in the application
How do you handle exceptions in an MVC application?
By using exception handling middleware or try-catch blocks in action methods
What is the purpose of the Layout
property in a View?
To define a common layout page for all or selected Views
How can you use Html.TextBoxFor
in a View?
To generate an HTML text input element bound to a model property