Unit 3: Backend Development Using Asp.Net - Practice Quiz

INT402 — Modern Web Programming Tools And Techniques 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which folder normally stores static files such as CSS, JavaScript, and images in an ASP.NET Core project?

ASP.NET Core Project Folder Structure Easy
A. Models
B. Controllers
C. wwwroot
D. Views

2 Which folder commonly contains MVC controller classes in an ASP.NET Core application?

ASP.NET Core Project Folder Structure Easy
A. Controllers
B. Properties
C. wwwroot
D. Views

3 Which command creates a new ASP.NET Core MVC project using the .NET CLI?

Building a Web Application using ASP.NET Core Easy
A. dotnet add mvc
B. dotnet run mvc
C. dotnet new mvc
D. dotnet build mvc

4 In the MVC pattern, which component is mainly responsible for displaying the user interface?

Understanding MVC Pattern and Model-View-Controller Communication Easy
A. Middleware
B. View
C. Controller
D. Model

5 In MVC, which component receives user input and coordinates between the Model and the View?

Understanding MVC Pattern and Model-View-Controller Communication Easy
A. Layout
B. Session
C. View
D. Controller

6 What is an action method in an ASP.NET Core MVC controller?

Handling Requests in .NET Core MVC Core Easy
A. A file that stores CSS rules
B. A method that handles a request
C. A folder that contains images
D. A class that defines a database

7 Which result method is commonly used by a controller action to render a Razor view?

Handling Requests in .NET Core MVC Core Easy
A. Map()
B. Build()
C. Run()
D. View()

8 Which symbol is used to begin Razor code in a .cshtml file?

Razor View Engine and Razor Syntax Easy
A. $
B. @
C. #
D. %

9 Which file extension is normally used for Razor views in ASP.NET Core MVC?

Razor View Engine and Razor Syntax Easy
A. .mvcxml
B. .aspx
C. .cshtml
D. .razorjs

10 What is the usual name of the shared layout file in an ASP.NET Core MVC project?

Layout, Sections and View Start Easy
A. _ViewStart.cshtml
B. _Layout.cshtml
C. _Imports.cshtml
D. _Home.cshtml

11 What is the main purpose of _ViewStart.cshtml?

Layout, Sections and View Start Easy
A. Set common view settings
B. Store controller actions
C. Serve static resources
D. Define model properties

12 Which technique provides strongly typed data from a controller to a view?

Data Passing Techniques Easy
A. Passing a model
B. Adding a route
C. Using a query string
D. Creating a session

13 Which statement correctly describes ViewBag?

ViewBag and ViewData Easy
A. It is a validation tag
B. It is a dynamic object
C. It is a routing table
D. It is a static file

14 How are values commonly accessed from ViewData?

ViewBag and ViewData Easy
A. By a CSS class
B. By a string key
C. By a file path
D. By a route name

15 What is TempData mainly used for in ASP.NET Core MVC?

Working with TempData Easy
A. Serving static website files
B. Keeping data for a later request
C. Storing permanent application data
D. Defining controller route patterns

16 What does session state allow an application to do?

Sessions and State Management Easy
A. Replace all controller actions
B. Compile Razor files into CSS
C. Store user data across requests
D. Create database tables automatically

17 In the URL /Products/Details?id=5, which part is the query string?

Working with QueryString Easy
A. /Products
B. Details
C. Products
D. id=5

18 Which HTML element is used to create a form in an ASP.NET Core Razor view?

ASP.NET Core Forms Easy
A. <form>
B. <script>
C. <section>
D. <table>

19 What does model binding do in ASP.NET Core MVC?

Model Binding Easy
A. Creates layouts for every view
B. Converts CSS into Razor syntax
C. Stores images in the model folder
D. Maps request data to action parameters

20 Which data annotation marks a model property as mandatory?

Form Validations: Server Side and Client Side Easy
A. [Optional]
B. [Display]
C. [Required]
D. [Hidden]

21 An MVC application contains a reusable partial view named _ProductCard.cshtml. Where should it be placed so that views from multiple controllers can discover it by name?

ASP.NET Core Project Folder Structure Medium
A. Views/Shared
B. Views/Home
C. wwwroot/views
D. Controllers/Shared

22 A CSS file is stored at wwwroot/css/site.css. Which URL should a Razor view normally use to request it?

ASP.NET Core Project Folder Structure Medium
A. ~/wwwroot/css/site.css
B. ~/css/site.css
C. ~/Content/css/site.css
D. ~/Views/css/site.css

23 An ASP.NET Core MVC project has controllers and views, but conventional controller routes return 404. Which configuration is required?

Building a Web Application using ASP.NET Core Medium
A. Call AddRazorPages() and map static assets
B. Call AddHttpClient() and map a fallback route
C. Call AddDbContext() and map a health check
D. Call AddControllersWithViews() and map a controller route

24 A controller action retrieves an Order from a service and needs to display it. Which approach best follows MVC responsibilities?

Understanding MVC Pattern and Model-View-Controller Communication Medium
A. Generate all order HTML inside the controller
B. Pass the order model to a view that renders it
C. Store the order in middleware before rendering
D. Query the service directly from the Razor view

25 Given the route template {controller=Home}/{action=Index}/{id?}, which action signature can receive the value from /Products/Details/12 directly?

Handling Requests in .NET Core MVC Core Medium
A. IActionResult Details(int controller)
B. IActionResult Details(int id)
C. IActionResult Details(string action)
D. IActionResult Details(int product)

26 A form displays an edit page with GET /Products/Edit/5 and submits changes to the same action name. What is the clearest way to distinguish the two actions?

Handling Requests in .NET Core MVC Core Medium
A. Apply [ValidateAntiForgeryToken] to both actions only
B. Apply [Route] to one and [Authorize] to the other
C. Apply [HttpGet] to one and [HttpPost] to the other
D. Apply [FromBody] to one and [FromQuery] to the other

27 Inside a Razor view, which syntax correctly renders a list only when Model.Items contains at least one item?

Razor View Engine and Razor Syntax Medium
A. @{ if Model.Items.Any(): <ul>...</ul> }
B. @if (Model.Items.Any()) { <ul>...</ul> }
C. @when (Model.Items.Any()) { <ul>...</ul> }
D. <if test="Model.Items.Any()"><ul>...</ul></if>

28 A view begins with @model ProductViewModel. Which expression accesses the product name with compile-time type checking?

Razor View Engine and Razor Syntax Medium
A. @ViewData.Name
B. @ViewBag.Name
C. @TempData.Name
D. @Model.Name

29 A layout calls @RenderSection("Scripts", required: false). What happens when a content view does not define that section?

Layout, Sections and View Start Medium
A. The layout automatically loads site.js instead
B. The request fails with a missing-section exception
C. The page renders without content for that section
D. The view renders without using the layout at all

30 Several views in one folder must use _AdminLayout.cshtml without setting Layout in every file. Which file should define the layout?

Layout, Sections and View Start Medium
A. _ValidationScriptsPartial.cshtml
B. _ViewImports.cshtml
C. _ViewStart.cshtml
D. appsettings.json

31 A view displays a customer and a collection of recent orders. Which technique provides the strongest compile-time checking?

Data Passing Techniques Medium
A. Create a view model containing both values
B. Serialize both values into one query parameter
C. Place both values in separate ViewBag properties
D. Store both values in session before returning the view

32 A controller sets ViewData["Title"] = "Catalog". Which statement about reading the value in the same view is correct?

ViewBag and ViewData Medium
A. Neither can read it unless the value is copied into Model
B. Only ViewData["Title"] can read it because storage is separate
C. Both ViewData["Title"] and ViewBag.Title can read it
D. Only ViewBag.Title can read it because the value is a string

33 After creating a product, an action redirects to Index and must show a success message once. Which storage mechanism is most appropriate?

Working with TempData Medium
A. TempData
B. ViewBag
C. HttpContext.Items
D. ViewData

34 A view reads TempData["Notice"], but the notice must remain available for one more request. What should the application do?

Working with TempData Medium
A. Call TempData.ContainsKey("Notice") before reading it
B. Call TempData.Keep("Notice") after reading it
C. Call TempData.Clear() before returning the view
D. Call TempData.Remove("Notice") after reading it

35 An application calls HttpContext.Session.SetString(...), but session access fails because no session is configured. Which setup is required?

Sessions and State Management Medium
A. Register response caching, then call UseResponseCaching()
B. Register cookie policy, then call UseCookiePolicy()
C. Register MVC and authorization, then call UseAuthorization()
D. Register a distributed cache and session, then call UseSession()

36 A request is sent to /Products/Search?term=phone&page=2. Which action signature allows default model binding to receive both values?

Working with QueryString Medium
A. IActionResult Search(int term, string page)
B. IActionResult Search(string term, int page)
C. IActionResult Search(string query, int number)
D. IActionResult Search(string id, int index)

37 A Razor form uses asp-action="Create" and method post. Which Tag Helper binds an input to Product.Name and generates the expected field name?

ASP.NET Core Forms Medium
A. <input asp-for="Name" />
B. <input asp-action="Name" />
C. <input asp-page="Name" />
D. <input asp-route="Name" />

38 A POST action accepts CustomerViewModel model, and the form contains an input named Address.City. Which model structure can bind that value automatically?

Model Binding Medium
A. A model with a City field only in the controller
B. A model with an Address property containing a City property
C. A model with an Addresses collection containing no index
D. A model with one string property named AddressCity

39 A form posts Quantity=abc to an action whose view model has public int Quantity { get; set; }. What should the action expect?

Model Binding Medium
A. Model binding skips the action and returns HTTP 404 automatically
B. Model binding stores abc in the integer property without conversion
C. Model binding converts the value to 1 and keeps ModelState valid
D. Model binding records an error and ModelState becomes invalid

40 A view model has [Required] on Email. Client-side validation scripts are enabled, but a caller submits an invalid request directly. What must the POST action do?

Form Validations: Server Side and Client Side Medium
A. Trust the browser because [Required] blocks every submission
B. Redirect immediately so validation runs on the GET action
C. Check ViewData.Model after saving the data
D. Check ModelState.IsValid before saving the data

41 An MVC controller named ReportsController belongs to an area declared with [Area("Admin")]. The action executes return View(); from Index. Assuming default view-location conventions and that all possible files exist, which file is selected first?

ASP.NET Core Project Folder Structure Hard
A. /Views/Admin/Reports/Index.cshtml
B. /Areas/Admin/Views/Reports/Index.cshtml
C. /Areas/Admin/Reports/Views/Index.cshtml
D. /Views/Reports/Admin/Index.cshtml

42 Which middleware order correctly enables static files, endpoint routing, authentication, authorization, and conventional MVC controller execution?

Building a Web Application using ASP.NET Core Hard
A. UseStaticFiles → UseRouting → UseAuthentication → UseAuthorization → MapControllerRoute
B. MapControllerRoute → UseRouting → UseAuthentication → UseStaticFiles → UseAuthorization
C. UseRouting → UseStaticFiles → UseAuthorization → UseAuthentication → MapControllerRoute
D. UseAuthentication → MapControllerRoute → UseRouting → UseAuthorization → UseStaticFiles

43 A POST action receives an edited model. Invalid submissions must redisplay attempted values and validation messages, while valid submissions must avoid duplicate posting when the browser refreshes. Which controller flow best satisfies both requirements?

Understanding MVC Pattern and Model-View-Controller Communication Hard
A. Redirect to the GET action for both invalid and valid submissions
B. Return the view for both invalid and valid submissions
C. Return the view when invalid; redirect to the GET action when valid
D. Redirect to the GET action when invalid; return the view when valid

44 A controller defines both Edit(int id) and Edit(string slug) as public actions with no action constraints. Under the conventional route {controller}/{action}/{id?}, what normally happens for /Products/Edit/42?

Handling Requests in .NET Core MVC Core Hard
A. Action selection is ambiguous because parameter types do not choose the action
B. Edit(string slug) is selected because route values originate as strings
C. Edit(int id) is selected because 42 converts successfully to an integer
D. Both actions run, and MVC combines their resulting action results

45 A Razor view must render the encoded result of a generic method call FormatValue<int>(Model.Count). Which syntax correctly prevents Razor from interpreting <int> as markup?

Razor View Engine and Razor Syntax Hard
A. @(FormatValue<int>(Model.Count))
B. @{ FormatValue<int>(Model.Count); }
C. @FormatValue<int>(Model.Count)
D. @Html.Raw(FormatValue<int>(Model.Count))

46 A view defines @section Scripts { <script src="page.js"></script> }. Its layout calls @await RenderSectionAsync("Scripts", required: false). What is the resulting behavior?

Layout, Sections and View Start Hard
A. The section is rendered where declared inside the content view
B. The section is rendered once at the layout's RenderSectionAsync location
C. The section causes an exception because optional sections cannot be defined
D. The section is ignored because required is set to false

47 The root /Views/_ViewStart.cshtml assigns Layout = "_Root", while /Views/Orders/_ViewStart.cshtml assigns Layout = "_Orders". An Orders view renders a partial from the same folder. Which statement is correct?

Layout, Sections and View Start Hard
A. Both files run independently for the full view and partial, producing nested layouts
B. Only the root file runs for the full view, and _Root also wraps the partial
C. Both files run for the full view, _Orders wins, and the partial does not run them separately
D. Only the Orders file runs for the full view, and _Orders wraps the partial independently

48 After a POST, ModelState contains an attempted value of "abc" for Price. The controller changes model.Price to 100 and returns the same view. What will <input asp-for="Price" /> normally display?

Data Passing Techniques Hard
A. abc, because the attempted ModelState value has precedence
B. An empty value, because invalid numeric input is discarded
C. 0, because numeric conversion failure supplies the type default
D. 100, because the strongly typed model always has precedence

49 A controller executes ViewBag.Message = "first"; followed by ViewData["Message"] = "second";. What does the view render for @ViewBag.Message | @ViewData["Message"]?

ViewBag and ViewData Hard
A. second | first
B. second | second
C. first | second
D. first | first

50 Action A reads TempData["Notice"], calls TempData.Keep("Notice"), and then redirects to Action B. Action B reads the same key but does not call Keep or Peek. Which lifecycle is expected?

Working with TempData Hard
A. Both actions read the value, and it is removed after Action B
B. Only Action B reads the value, because Action A's read is deferred
C. Both actions read the value, and it remains for all later requests
D. Only Action A reads the value, and it is removed before Action B

51 Two parallel requests from the same browser both read a session counter as 5, increment it, and store 6. What conclusion is most accurate for ASP.NET Core session state?

Sessions and State Management Hard
A. Session values are immutable, so neither request can overwrite the stored counter
B. Session access is request-locking, so the final counter is guaranteed to become 7
C. Session values are transactional, so a write conflict automatically retries one request
D. Session access is non-locking, so both updates may succeed while one increment is lost

52 Given Search([FromQuery(Name = "tag")] string[] tags), what is bound for a request to /Search?tag=core&tag=mvc?

Working with QueryString Hard
A. An array containing core and mvc
B. A single string containing core,mvc
C. An array containing only mvc
D. A binding error caused by duplicate keys

53 An enabled checkbox is rendered using <input asp-for="IsActive" /> and is checked when submitted. With the default CheckBox Tag Helper behavior, which result is expected?

ASP.NET Core Forms Hard
A. The form sends true and false, and the Boolean property binds to true
B. The duplicate values cause model binding to reject the Boolean property
C. The form sends only true, and the Boolean property binds to true
D. The form sends false and true, and the Boolean property binds to false

54 An action parameter is Instructor instructor. The query string is ?Instructor.Id=7&Name=Ada. Assuming Instructor has Id and Name properties, what is the typical binding result?

Model Binding Hard
A. Id remains 0, while Name becomes Ada because unprefixed keys take precedence
B. Id becomes 7, and Name becomes Ada because prefixed and unprefixed keys are merged
C. Id becomes 7, while Name remains unset because the binder chose the Instructor prefix
D. Both properties remain unset because every query key must use exactly the same prefix

55 A form initially has working jQuery unobtrusive validation. A required input with valid data-val-* attributes is later inserted using AJAX, but client validation ignores it. Server validation still detects the error. What is the appropriate client-side fix?

Form Validations: Server Side and Client Side Hard
A. Call ModelState.Clear() immediately before submitting the form
B. Add [ValidateAntiForgeryToken] to the receiving controller action
C. Replace the validation attributes with HTML required only
D. Reparse the inserted container with $.validator.unobtrusive.parse(...)

56 Nullable reference types are enabled, and a view model declares public string Title { get; set; } without [Required]. An empty posted value is converted to null. Under the default MVC validation configuration, what should be expected?

Form Validations: Server Side and Client Side Hard
A. Binding fails before validation because reference properties cannot receive null
B. Validation fails because a non-nullable reference property is treated as implicitly required
C. Validation succeeds because only an explicit [Required] attribute triggers validation
D. Validation succeeds because implicit required validation always permits null values

57 A JavaScript client posts JSON to an action protected by [ValidateAntiForgeryToken]. The page already contains a generated antiforgery hidden input. Which approach correctly supports the JSON request?

ASP.NET Core Forms Hard
A. Change the action to HTTP GET because antiforgery validation applies only to JSON POSTs
B. Copy the hidden token into the JSON model under any property name chosen by the client
C. Configure an antiforgery header name and copy the hidden token value into that request header
D. Send only the antiforgery cookie because the request cookie alone proves authenticity

58 An application uses the default cookie-based TempData provider and attempts TempData["Order"] = order, where order is a custom complex object. Which solution is generally appropriate?

Working with TempData Hard
A. Store the object directly because TempData automatically serializes every CLR type
B. Cast the object to dynamic so the cookie provider accepts its runtime members
C. Place the object in ViewData because ViewData automatically survives a redirect
D. Serialize the object to a compact string and deserialize it after retrieval

59 A controller has [ApiController], and an action parameter fails validation during model binding. No custom invalid-model-state configuration is present. What normally occurs?

Handling Requests in .NET Core MVC Core Hard
A. MVC returns an automatic HTTP 400 response before the action body executes
B. MVC redirects to the same action and stores validation errors in TempData
C. The action executes with null and MVC discards all model-state errors
D. The action executes and must always test ModelState.IsValid manually

60 An application runs on two load-balanced instances without sticky sessions. Users intermittently lose session data when requests reach different instances. Which architecture best addresses the underlying problem?

Sessions and State Management Hard
A. Store larger objects in each instance's session and disable cookie consent
B. Move session middleware after endpoint execution and enable response buffering
C. Use separate in-memory caches and increase the session idle timeout
D. Use a shared distributed session cache and share required Data Protection keys