Try to solve 5 ASP.NET (Core) MVC interview questions below. Hints can help you find answers to questions you are having trouble with.

1. Action Attributes

Action attributes Actions
   
Easy 

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
   
Easy  

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
   
Easy 

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.

<html>
<body>
  <h1>Name: </h1>
  <p>Calories: </p>
  <p>Ingredients:</p>
  <ul>
    @foreach (var ingredient in )
    {
        <li></li>
    }
  </ul>
</body>
</html>
   


4. User Controller

Action attributes Actions HTTP Routing
   
Easy 

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# 7.0, .NET Framework 4.7  
 


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


5. Address Controller

Action attributes Actions URL routing
   
Easy 

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

@model Address

<!DOCTYPE html>
<html>
<head>
  <title>Create a new address</title>
</head>
<body>
  <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" />
  </form>
</body>
</html>

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# 7.0, .NET Framework 4.7  
 


  •   /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

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.