ASP.NET Core MVC Interview

Controllers, Actions, Model Binding & Action Results

ASP.NET Core MVC interview questions covering controllers, actions, model binding & action results.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
26
JuniorBeginner

What are action selectors in ASP.NET Core MVC?

Action selectors help MVC determine which action method can handle a request. HTTP method attributes such as HttpGet, HttpPost, HttpPut, and HttpDelete constrain an action to particular request methods, while routing attributes can further constrain the URL.

27
JuniorBeginner

What is the purpose of the [HttpGet] attribute?

HttpGet restricts an action to HTTP GET requests. GET actions are normally used to retrieve or display information and should not perform state-changing operations.

28
JuniorBeginner

What is the purpose of the [HttpPost] attribute?

HttpPost restricts an action to HTTP POST requests. POST actions commonly process form submissions that create or change server-side state.

29
JuniorBeginner

What is the Post/Redirect/Get pattern in ASP.NET Core MVC?

Post/Redirect/Get (PRG) is a pattern where a successful POST request returns a redirect instead of directly rendering the final page. The browser then performs a GET request for the redirected URL.

30
JuniorBeginner

What does the [NonAction] attribute do?

NonAction tells MVC that a public method on a controller must not be treated as an action. It can be useful for public helper methods, although private or protected helper methods are often preferable when possible.

31
JuniorBeginner

What is ActionNameAttribute in ASP.NET Core MVC?

ActionNameAttribute gives an action a different externally visible action name from its C# method name. This can be useful when two methods need distinct C# names but should participate in routing under a desired action name.

32
JuniorBeginner

What is model binding in ASP.NET Core MVC?

Model binding converts incoming request data into action parameters and model objects. It can obtain values from route data, query strings, form fields, and other supported value providers.

33
JuniorBeginner

What request sources can MVC use during model binding?

MVC can bind values from several request sources, including form fields, route values, query-string parameters, uploaded files, and services when explicitly requested. In controller applications, attributes such as FromRoute, FromQuery, FromForm, and FromServices can make the intended source explicit.

34
JuniorBeginner

What is the difference between [FromRoute], [FromQuery], and [FromForm]?

FromRoute tells MVC to obtain a value from route data, FromQuery obtains it from the query string, and FromForm obtains it from submitted form fields. These attributes make the source explicit and can remove ambiguity.

35
JuniorBeginner

How does MVC bind complex objects?

For a complex object, model binding creates the object and attempts to populate its bindable properties from matching request keys. Nested property names and indexed collection names can also be bound when the submitted field names follow the expected format.

36
JuniorBeginner

What is overposting in ASP.NET Core MVC?

Overposting occurs when model binding allows a client to set properties that the UI was not intended to modify. This is particularly dangerous when persistence entities contain fields such as IsAdmin, Approved, OwnerId, PriceOverride, or internal status values.

37
JuniorBeginner

What is ModelState in ASP.NET Core MVC?

ModelState contains the results of model binding and model validation for the current request. It stores attempted values and validation errors associated with fields.

38
JuniorBeginner

How does validation work in ASP.NET Core MVC?

After model binding, MVC validates the bound model using configured validation mechanisms. Data annotation attributes such as Required, StringLength, Range, and Compare are commonly used on input models.

39
JuniorBeginner

What is the difference between server-side and client-side validation?

Server-side validation executes on the server and must be treated as the authoritative validation layer. Client-side validation runs in the browser and improves usability by displaying errors without a full request when supported.

40
JuniorBeginner

How can you add a custom validation error to ModelState?

A controller can add an error manually with ModelState.AddModelError. This is useful for validation that depends on application logic or multiple fields, such as checking whether a username is already registered.

41
JuniorBeginner

What is a ViewResult?

ViewResult is an IActionResult that renders a Razor view. Controller.View() creates a ViewResult and can optionally specify a view name and model.

42
JuniorBeginner

What is RedirectToActionResult?

RedirectToActionResult instructs the browser to make a new request to an MVC action. It is commonly created with RedirectToAction and is heavily used with the Post/Redirect/Get pattern.

43
JuniorBeginner

What is the difference between Redirect, RedirectToAction, and RedirectToRoute?

Redirect sends the client to a specified URL. RedirectToAction generates a URL for an MVC controller/action, while RedirectToRoute generates a URL using a named route or route values.

44
JuniorBeginner

What are ContentResult and JsonResult?

ContentResult returns text content with an optional content type and status code. JsonResult serializes an object as JSON.

45
JuniorBeginner

How do NotFound, BadRequest, and StatusCode work in MVC actions?

Controller helper methods can create HTTP status-code results. NotFound returns 404, BadRequest returns 400, Unauthorized returns 401, and StatusCode can produce a specified status code.

46
JuniorBeginner

How do you return a file from an ASP.NET Core MVC action?

Controller.File provides overloads for returning file bytes, streams, or physical/virtual files with an appropriate content type and optional download filename. File responses are useful for generated reports, documents, images, and exports.

47
JuniorBeginner

What is asynchronous action programming in ASP.NET Core MVC?

An MVC action can be asynchronous and return Task<IActionResult> or another task-based result. Async actions are especially useful for database, HTTP, file, and other I/O operations because the request thread does not need to block while waiting for the I/O to complete.

48
JuniorBeginner

Why should CancellationToken be passed from MVC actions to services?

ASP.NET Core exposes a cancellation token that is signaled when the HTTP request is aborted. Passing it to asynchronous database, HTTP, and application-service operations allows unnecessary work to stop when supported.

49
JuniorBeginner

How should exceptions be handled in MVC controllers?

Controllers should generally not contain repetitive try/catch blocks for every unexpected exception. Centralized exception-handling middleware or an exception handler can log unexpected failures and return an appropriate error response or page.

50
JuniorBeginner

What are best practices for designing MVC controllers and actions?

Keep controllers focused on HTTP and application-flow concerns: accept input, validate it, call application services, and choose the response. Use dedicated ViewModels or input models rather than binding database entities directly, and use dependency injection instead of constructing infrastructure dependencies inside actions.