ASP.NET Core MVC Interview

Testing, AJAX/JavaScript Integration, Localization & Advanced MVC

ASP.NET Core MVC interview questions covering testing, ajax/javascript integration, localization & advanced mvc.

25 Questions Filter by level

Interview questions

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

25 Results
151
SeniorAdvanced

What is unit testing in ASP.NET Core MVC?

Unit testing verifies a small unit of application behavior in isolation, such as a controller action or service method. Dependencies are normally replaced with test doubles so the test focuses on the unit's own decisions rather than databases, networks, or the full ASP.NET Core pipeline.

152
SeniorAdvanced

What should be tested in an MVC controller unit test?

Test observable controller behavior rather than framework implementation details. Typical assertions include the returned result type, selected view, ViewModel, redirect target, status result, and whether an application service was called with the expected input.

153
SeniorAdvanced

How do you test an MVC action when ModelState is invalid?

In a direct controller unit test, automatic model validation does not run because the MVC pipeline is not executing. The test can add a ModelState error manually and then verify that the action redisplays the form and does not call the write operation.

154
SeniorAdvanced

What is integration testing in ASP.NET Core MVC?

Integration testing exercises multiple application components together through a realistic ASP.NET Core request pipeline. It can verify routing, middleware, filters, model binding, authorization, controller execution, dependency injection, and HTTP responses.

155
SeniorAdvanced

What is WebApplicationFactory in ASP.NET Core testing?

WebApplicationFactory<TEntryPoint> creates a test host for an ASP.NET Core application and provides HttpClient instances that send requests through the application's pipeline. It is provided by the Microsoft.AspNetCore.Mvc.Testing package.

156
SeniorAdvanced

What is the difference between a mock, stub, and fake in MVC tests?

These are categories of test doubles. A stub supplies predetermined responses, a mock is commonly used to verify interactions or expectations, and a fake provides a lightweight working implementation such as an in-memory repository designed for tests.

157
SeniorAdvanced

How can AJAX be used with an ASP.NET Core MVC application?

AJAX allows browser JavaScript to send HTTP requests without performing a full-page navigation. An MVC action can return JSON, HTML fragments, status codes, or other content that JavaScript uses to update part of the page.

158
SeniorAdvanced

How can an MVC action return a partial view for an AJAX request?

An action can prepare a ViewModel and return PartialView with the partial view name and model. Browser JavaScript can request the action and place the returned HTML into a selected DOM element.

159
SeniorAdvanced

How should anti-forgery protection be handled with JavaScript POST requests?

A state-changing request authenticated by browser cookies remains exposed to CSRF even when it is sent through JavaScript. The request should provide the anti-forgery token expected by the server, commonly by reading a generated token from the page and sending it in a form value or configured request header.

160
SeniorAdvanced

What is the difference between returning JSON and returning a partial view?

Returning JSON sends structured data that client-side JavaScript must interpret and render. Returning a partial view sends server-rendered HTML that can be inserted into the page directly.

161
SeniorAdvanced

What are View Components and when are they preferable to partial views?

A partial view is mainly reusable Razor markup and receives data from its caller. A View Component is a reusable rendering component with its own invocation logic and can obtain the data needed to render itself.

162
SeniorAdvanced

How do you invoke a View Component from Razor?

A View Component can be invoked with Component.InvokeAsync or through a View Component Tag Helper when its naming and registration conventions are satisfied. The invocation can pass arguments that match the component's Invoke or InvokeAsync parameters.

163
SeniorAdvanced

What is Razor view localization?

Razor view localization allows user-facing text in views to be selected according to the current culture. ASP.NET Core provides localization abstractions such as IViewLocalizer and IStringLocalizer.

164
SeniorAdvanced

How is request localization configured in ASP.NET Core?

Request localization middleware determines the culture and UI culture for a request using configured culture providers. Providers can obtain culture information from sources such as query strings, cookies, or request headers.

165
SeniorAdvanced

What is the difference between culture and UI culture?

Culture primarily affects culture-sensitive formatting and parsing such as numbers, dates, and currency. UI culture is used to select localized resources for user-interface text.

166
SeniorAdvanced

What is a custom Tag Helper?

A custom Tag Helper is a server-side component that participates in rendering selected HTML elements or custom tag-like markup in Razor. It can inspect attributes, modify output, or generate reusable presentation behavior.

167
SeniorAdvanced

What is a custom model binder?

A custom model binder controls how request data is converted into a particular parameter or model type when the default binding behavior is not sufficient. It implements model-binding contracts and can be associated with a type or configured through a provider.

168
SeniorAdvanced

What is a custom validation attribute?

A custom validation attribute derives from ValidationAttribute and implements reusable validation logic that can be applied declaratively to model properties or types.

169
SeniorAdvanced

What is an MVC convention?

MVC conventions allow an application to customize model metadata, controller/action discovery, routing behavior, and other MVC configuration according to project-wide rules. Examples include application model conventions that modify controllers, actions, selectors, or route models during application startup.

170
SeniorAdvanced

What is application model customization in MVC?

During startup, MVC builds an application model describing discovered controllers, actions, parameters, selectors, routes, and related metadata. Application model conventions can inspect or modify this model before endpoints are finalized.

171
SeniorAdvanced

How can MVC views be organized in a large application?

Large applications can use Areas, feature-oriented folders, shared layouts, partial views, View Components, and consistent ViewModels to prevent the Views folder from becoming difficult to navigate. The chosen organization should align with functional boundaries rather than arbitrary technical splitting.

172
SeniorAdvanced

What is a custom view location and why might an application use one?

MVC normally searches conventional view locations such as Views/{Controller}/{View}. An application can customize view-location expansion when it uses a different organizational convention, for example feature folders.

173
SeniorAdvanced

How should client-side JavaScript and server-side MVC responsibilities be separated?

The server remains responsible for authentication, authorization, validation, business rules, persistence, and trusted state transitions. JavaScript can improve interaction by submitting requests asynchronously, updating DOM elements, and performing convenience validation, but client behavior cannot be trusted as enforcement.

174
SeniorAdvanced

When should you use MVC instead of a client-side SPA architecture?

Server-rendered MVC is a strong choice when the application is page-oriented, benefits from straightforward SEO and initial rendering, uses forms and navigation heavily, or does not require extensive client-side state and interaction.

175
SeniorAdvanced

What are best practices for testing and advanced MVC development?

Place most business behavior in testable application/domain services and keep controllers focused on HTTP flow. Use controller unit tests for meaningful action decisions and integration tests for routing, middleware, filters, authentication, model binding, and other pipeline behavior.