ASP.NET MVC MCQs

What does MVC stand for in ASP.NET MVC? A) Model View Control B) Model View Controller C) Module View Controller D) Model View Config Answer: B) Model View Controller Which component of MVC handles user input? A) Model B) View C) Controller D) Database Answer: C) Controller In ASP.NET MVC, which component is responsible for the application’s business logic? A) View B) Model C) Controller D) Route Answer: B) Model Which method in a controller is invoked by default in ASP.NET MVC? A) Main() B) Index() C) Start() D) Init() Answer: B) Index() Which file is used to define routes in an ASP.NET MVC application? A) RouteConfig.cs B) Startup.cs C) Web.config D) AppSettings.json Answer: A) RouteConfig.cs In ASP.NET MVC, what is a View? A) A component that handles user input B) A component that renders the user interface C) A class that handles database connections D) A controller method Answer: B) A component that renders the user interface What is the purpose of the ViewBag in ASP.NET MVC? A) To store temporary data for the current request B) To manage session state C) To handle routing D) To store permanent data Answer: A) To store temporary data for the current request Which of the following is NOT a return type of a controller action in ASP.NET MVC? A) ActionResult B) JsonResult C) FileResult D) DataTable Answer: D) DataTable In ASP.NET MVC, what is the role of the ActionResult class? A) To define a model B) To return a result from a controller action C) To process user inputs D) To handle routing Answer: B) To return a result from a controller action Which HTML helper is used to create a form in ASP.NET MVC? A) Html.TextBox B) Html.Label C) Html.BeginForm D) Html.Form Answer: C) Html.BeginForm What does Scaffold mean in ASP.NET MVC? A) Automatically generating code B) Writing code manually C) Optimizing the application D) Debugging the application Answer: A) Automatically generating code Which feature allows you to bind form values to a model in ASP.NET MVC? A) Model Binding B) ViewData C) ViewBag D) Routing Answer: A) Model Binding What is the use of TempData in ASP.NET MVC? A) To persist data between requests B) To store data temporarily between two consecutive requests C) To manage session data D) To store user inputs Answer: B) To store data temporarily between two consecutive requests Which method is used to pass data from a controller to a view in ASP.NET MVC? A) Redirect B) RedirectToAction C) View D) None of the above Answer: C) View What is Razor in ASP.NET MVC? A) A database technology B) A templating engine for creating dynamic views C) A CSS framework D) A JavaScript library Answer: B) A templating engine for creating dynamic views How do you define a route in ASP.NET MVC? A) In the Web.config file B) In the RouteConfig.cs file C) In the View file D) In the Global.asax file Answer: B) In the RouteConfig.cs file Which method is used to return JSON data from a controller in ASP.NET MVC? A) Json() B) ReturnJson() C) View() D) Data() Answer: A) Json() Which method is used to handle GET requests in ASP.NET MVC? A) [HttpPost] B) [HttpGet] C) [HttpPut] D) [HttpDelete] Answer: B) [HttpGet] What is the default folder structure for views in ASP.NET MVC? A) Views/ControllerName/ActionName.cshtml B) ControllerName/Views/ActionName.cshtml C) Views/ActionName/ControllerName.cshtml D) Views/ActionName.cshtml Answer: A) Views/ControllerName/ActionName.cshtml Which helper method is used to create a link in ASP.NET MVC? A) Html.ActionLink B) Html.HyperLink C) Html.Link D) Html.Url Answer: A) Html.ActionLink What does ViewData in ASP.NET MVC do? A) Stores data for the current request B) Stores data for the entire session C) Persists data across multiple requests D) Stores data permanently Answer: A) Stores data for the current request Which feature in ASP.NET MVC allows client-side validation of forms? A) Data Annotations B) ViewBag C) Partial Views D) Routing Answer: A) Data Annotations In ASP.NET MVC, how do you return a different view from an action method? A) Return View(“ViewName”) B) Redirect(“ViewName”) C) Render(“ViewName”) D) Action(“ViewName”) Answer: A) Return View(“ViewName”) What is the purpose of @Html.Partial() in ASP.NET MVC? A) To render a portion of a view B) To create a controller C) To manage routing D) To return a model Answer: A) To render a portion of a view Which method is used to render a view without a layout in ASP.NET MVC? A) return View(); B) return PartialView(); C) return Json(); D) return EmptyView(); Answer: B) return PartialView(); Which attribute in ASP.NET MVC is used to restrict access to a controller or action? A) [HttpPost] B) [Authorize] C) [HttpGet] D) [AllowAnonymous] Answer: B) [Authorize] What is the purpose of @Html.ValidationMessageFor() in ASP.NET MVC? A) Display error messages for a specific field B) Create a validation form C) Render the form controls D) Redirect the user Answer: A) Display error messages for a specific field Which of the following is NOT a valid return type in ASP.NET MVC? A) ViewResult B) FileResult C) PartialViewResult D) HtmlResult Answer: D) HtmlResult What is the role of ActionFilters in ASP.NET MVC? A) To apply cross-cutting concerns like logging or authorization B) To manage form submissions C) To optimize application performance D) To handle exceptions Answer: A) To apply cross-cutting concerns like logging or authorization Which action filter is used to cache the output of a controller action? A) OutputCache B) Authorize C) HandleError D) RequireHttps Answer: A) OutputCache How can you inject a service into a controller in ASP.NET MVC? A) By using constructor injection B) By using the ViewBag C) By using ViewData D) By using Model Binding Answer: A) By using constructor injection Which file is responsible for configuring dependency injection in ASP.NET MVC? A) Startup.cs B) RouteConfig.cs C) Web.config D) App.config Answer: A) Startup.cs How do you handle errors globally in ASP.NET MVC? A) By using the Global.asax file B) By using a custom error handler in Web.config C) By using an exception filter D) By overriding the OnException method in a controller Answer: C) By using an exception filter Which view engine is commonly used in ASP.NET MVC? A) Razor B) PHP C) JSP D) Python Answer: A) Razor What does @model keyword do in a Razor view? A) Declares the type of model being passed to the view B) Defines a new model C) Imports a controller D) Declares a method Answer: A) Declares the type of model being passed to the view What is the purpose of @Html.LabelFor() in ASP.NET MVC? A) To generate a label for a specific model property B) To create a button C) To submit a form D) To display validation messages Answer: A) To generate a label for a specific model property Which attribute is used for server-side form validation in ASP.NET MVC? A) [ValidateAntiForgeryToken] B) [HttpPost] C) [Authorize] D) [AllowAnonymous] Answer: A) [ValidateAntiForgeryToken] What is Unobtrusive JavaScript in ASP.NET MVC? A) JavaScript that doesn’t interfere with HTML B) JavaScript that handles all server-side validation C) JavaScript code injected directly into the controller D) A technique that uses data attributes for client-side validation Answer: D) A technique that uses data attributes for client-side validation Which method is used to update a record in ASP.NET MVC? A) Update() B) Save() C) Edit() D) Submit() Answer: C) Edit() What is ViewStart.cshtml in ASP.NET MVC? A) A file that defines the layout for all views in an application B) A controller file C) A JavaScript file D) A routing file Answer: A) A file that defines the layout for all views in an application What is the purpose of ViewBag in ASP.NET MVC? A) To store data between requests B) To pass data from controller to view C) To handle routing D) To manage model validation Answer: B) To pass data from controller to view Which of the following is the default view engine in ASP.NET MVC? A) Razor B) WebForms C) JSP D) Blade Answer: A) Razor What is the role of RouteConfig in ASP.NET MVC? A) To define URL routing patterns B) To connect the application to the database C) To manage controller actions D) To handle errors Answer: A) To define URL routing patterns What does HttpPost attribute indicate in ASP.NET MVC? A) The action method responds to HTTP POST requests B) The action method handles GET requests C) The method sends data to the client D) The method processes routing Answer: A) The action method responds to HTTP POST requests Which of the following is used to return a partial view in ASP.NET MVC? A) return PartialView() B) return View() C) return Json() D) return File() Answer: A) return PartialView() What does TempData do in ASP.NET MVC? A) Stores data temporarily and is available for the next request only B) Stores data permanently in the session C) Shares data between different controllers D) Manages the model state Answer: A) Stores data temporarily and is available for the next request only What is the purpose of @Html.TextBoxFor() in ASP.NET MVC? A) To create an input element for a model property B) To display a label C) To handle form validation D) To display data Answer: A) To create an input element for a model property
All Copyrights Reserved 2025 Reserved by T4Tutorials