ASP.NET (Core) MVC Interview Questions

Practice for ASP.NET (Core) MVC interviews by solving TestDome questions. Our interview questions are used by more than 7,000 companies and 450,000 individual test takers.

Jobseekers: Certify Your Knowledge

Take a Certification Test

Companies: Use Our Tests for Screening

Buy a Pack Of Candidates

Need to practice your ASP.NET (Core) MVC skills for an upcoming job interview? Try solving these ASP.NET (Core) MVC interview questions that test knowledge of Razor, Action methods and attributes, and other skills. We’ll provide feedback on your answers, and you can use a hint if you get stuck.

These ASP.NET (Core) MVC interview questions are examples of real tasks used by employers to screen candidates for web development jobs that require knowledge of the MVC pattern, ASP.NET and the .NET Framework in order to build robust and scalable web applications.

1. Action Attributes

Action attributes Actions

Which statements are true about action attributes in ASP.NET (Core) MVC?

(Select all acceptable answers.)

If an action returns JSON data, it must be decorated with the JsonResult attribute.
There is a built-in attribute for defining view name.
The ValidateAntiForgeryToken attribute prevents CSRF attacks.
The ActionName attribute allows usage of a different action name than the method name.

2. Passing Data

MVC pattern

Select all the methods that can be used to pass data from the controller to the view.

(Select all acceptable answers.)

By setting properties on the model that is passed to the view.
By setting properties on the web controls that the view contains.
By using the view's helper methods.
By using ViewData dictionary.

3. Meal View

Razor View

Consider the following C# model:

public class Meal
    public string Name { get; set; }
    public double Calories { get; set; }
    public List<string> Ingredients { get; set; }

The following template for Razor view engine accepts a Meal as model. Fill in the blanks with the simplest variants so that correct properties are printed.

  <h1>Name: </h1>
  <p>Calories: </p>
    @foreach (var ingredient in )

4. User Controller

Action attributes Actions HTTP Routing

Add appropriate routing attributes to the GetUsers and GetUserById actions so that:

  • GetUsers should activate on URL "/users".
  • GetUserById should activate on URLs "/users/userId" where userId is a string that represents the id of the user.
ASP.NET Core MVC Web 2 app, C# 8.0, .NET Framework 4.8  

  •   The GetUser action is correctly routed: Wrong answer
  •   The GetUserById action is correctly mapped: Wrong answer

5. Address Controller

Action attributes Actions URL routing

Consider the following view, provided here and below, which is placed in Views/Address/Create.cshtml:

@model Address

<!DOCTYPE html>
  <title>Create a new address</title>
  <form method="post" action="/user/address/save">
    <label asp-for="Street">Street:</label>
    <input type="text" asp-for="Street" />
    <label asp-for="City">City:</label>
    <input type="text" asp-for="City" />
    <input type="submit" value="Submit" />

Add actions to the AddressController so that:

  • On requests to "user/address/create", the view above should be returned.
  • On submitting the form from the view above, AddressController should add the Address that was submitted into the AddressController.addresses field and then redirect to the "user/address/create" URL.

Actions should use attribute routing.

ASP.NET Core MVC Web 2 app, C# 8.0, .NET Framework 4.8  

  •   /user/address/create and /user/address/save URLs are mapped to distinct actions: Wrong answer
  •   /user/address/create URL returns expected view: Wrong answer
  •   Address is added to the AddressController.addresses list when the form is submitted: Wrong answer
  •   After saving the address, user is redirected to /user/address/create URL: Wrong answer

If you feel ready, take one of our timed public ASP.NET (Core) MVC Interview Questions tests:

ASP.NET (Core) MVC, HTML/CSS, JavaScript, C#, and SQL Online Test (Easy / Hard)

Not exactly what you are looking for? Go to our For Jobseekers section.
Dashboard Start Trial Sign In Home Tour Tests Questions Pricing For Jobseekers