Unit 3: Backend Development Using Asp.Net - Practice Quiz
1 Which folder normally stores static files such as CSS, JavaScript, and images in an ASP.NET Core project?
2 Which folder commonly contains MVC controller classes in an ASP.NET Core application?
3 Which command creates a new ASP.NET Core MVC project using the .NET CLI?
4 In the MVC pattern, which component is mainly responsible for displaying the user interface?
5 In MVC, which component receives user input and coordinates between the Model and the View?
6 What is an action method in an ASP.NET Core MVC controller?
7 Which result method is commonly used by a controller action to render a Razor view?
8
Which symbol is used to begin Razor code in a .cshtml file?
9 Which file extension is normally used for Razor views in ASP.NET Core MVC?
10 What is the usual name of the shared layout file in an ASP.NET Core MVC project?
11
What is the main purpose of _ViewStart.cshtml?
12 Which technique provides strongly typed data from a controller to a view?
13
Which statement correctly describes ViewBag?
14
How are values commonly accessed from ViewData?
15
What is TempData mainly used for in ASP.NET Core MVC?
16 What does session state allow an application to do?
17
In the URL /Products/Details?id=5, which part is the query string?
18 Which HTML element is used to create a form in an ASP.NET Core Razor view?
<form>
<script>
<section>
<table>
19 What does model binding do in ASP.NET Core MVC?
20 Which data annotation marks a model property as mandatory?
[Optional]
[Display]
[Required]
[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?
Views/Shared
Views/Home
wwwroot/views
Controllers/Shared
22
A CSS file is stored at wwwroot/css/site.css. Which URL should a Razor view normally use to request it?
~/wwwroot/css/site.css
~/css/site.css
~/Content/css/site.css
~/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?
AddRazorPages() and map static assets
AddHttpClient() and map a fallback route
AddDbContext() and map a health check
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?
25
Given the route template {controller=Home}/{action=Index}/{id?}, which action signature can receive the value from /Products/Details/12 directly?
IActionResult Details(int controller)
IActionResult Details(int id)
IActionResult Details(string action)
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?
[ValidateAntiForgeryToken] to both actions only
[Route] to one and [Authorize] to the other
[HttpGet] to one and [HttpPost] to the other
[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?
@{ if Model.Items.Any(): <ul>...</ul> }
@if (Model.Items.Any()) { <ul>...</ul> }
@when (Model.Items.Any()) { <ul>...</ul> }
<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?
@ViewData.Name
@ViewBag.Name
@TempData.Name
@Model.Name
29
A layout calls @RenderSection("Scripts", required: false). What happens when a content view does not define that section?
site.js instead
30
Several views in one folder must use _AdminLayout.cshtml without setting Layout in every file. Which file should define the layout?
_ValidationScriptsPartial.cshtml
_ViewImports.cshtml
_ViewStart.cshtml
appsettings.json
31 A view displays a customer and a collection of recent orders. Which technique provides the strongest compile-time checking?
ViewBag properties
32
A controller sets ViewData["Title"] = "Catalog". Which statement about reading the value in the same view is correct?
Model
ViewData["Title"] can read it because storage is separate
ViewData["Title"] and ViewBag.Title can read it
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?
TempData
ViewBag
HttpContext.Items
ViewData
34
A view reads TempData["Notice"], but the notice must remain available for one more request. What should the application do?
TempData.ContainsKey("Notice") before reading it
TempData.Keep("Notice") after reading it
TempData.Clear() before returning the view
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?
UseResponseCaching()
UseCookiePolicy()
UseAuthorization()
UseSession()
36
A request is sent to /Products/Search?term=phone&page=2. Which action signature allows default model binding to receive both values?
IActionResult Search(int term, string page)
IActionResult Search(string term, int page)
IActionResult Search(string query, int number)
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?
<input asp-for="Name" />
<input asp-action="Name" />
<input asp-page="Name" />
<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?
City field only in the controller
Address property containing a City property
Addresses collection containing no index
AddressCity
39
A form posts Quantity=abc to an action whose view model has public int Quantity { get; set; }. What should the action expect?
abc in the integer property without conversion
1 and keeps ModelState valid
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?
[Required] blocks every submission
ViewData.Model after saving the data
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?
/Views/Admin/Reports/Index.cshtml
/Areas/Admin/Views/Reports/Index.cshtml
/Areas/Admin/Reports/Views/Index.cshtml
/Views/Reports/Admin/Index.cshtml
42 Which middleware order correctly enables static files, endpoint routing, authentication, authorization, and conventional MVC controller execution?
UseStaticFiles → UseRouting → UseAuthentication → UseAuthorization → MapControllerRoute
MapControllerRoute → UseRouting → UseAuthentication → UseStaticFiles → UseAuthorization
UseRouting → UseStaticFiles → UseAuthorization → UseAuthentication → MapControllerRoute
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?
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?
Edit(string slug) is selected because route values originate as strings
Edit(int id) is selected because 42 converts successfully to an integer
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?
@(FormatValue<int>(Model.Count))
@{ FormatValue<int>(Model.Count); }
@FormatValue<int>(Model.Count)
@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?
RenderSectionAsync location
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?
_Root also wraps the partial
_Orders wins, and the partial does not run them separately
_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?
abc, because the attempted ModelState value has precedence
0, because numeric conversion failure supplies the type default
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"]?
second | first
second | second
first | second
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?
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?
7
52
Given Search([FromQuery(Name = "tag")] string[] tags), what is bound for a request to /Search?tag=core&tag=mvc?
core and mvc
core,mvc
mvc
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?
true and false, and the Boolean property binds to true
true, and the Boolean property binds to true
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?
Id remains 0, while Name becomes Ada because unprefixed keys take precedence
Id becomes 7, and Name becomes Ada because prefixed and unprefixed keys are merged
Id becomes 7, while Name remains unset because the binder chose the Instructor 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?
ModelState.Clear() immediately before submitting the form
[ValidateAntiForgeryToken] to the receiving controller action
required only
$.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?
null
[Required] attribute triggers validation
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?
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?
dynamic so the cookie provider accepts its runtime members
ViewData because ViewData automatically survives a redirect
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?
null and MVC discards all model-state errors
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?
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →