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. wwwroot
B. Controllers
C. Models
D. Views

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

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

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 new mvc
C. dotnet build mvc
D. dotnet run 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. Controller
B. Middleware
C. Model
D. View

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. Controller
B. View
C. Session
D. Layout

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

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

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. Run()
B. View()
C. Map()
D. Build()

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. .cshtml
B. .aspx
C. .mvcxml
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. _Imports.cshtml
B. _Home.cshtml
C. _Layout.cshtml
D. _ViewStart.cshtml

11 What is the main purpose of _ViewStart.cshtml?

Layout, Sections and View Start Easy
A. Store controller actions
B. Set common view settings
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. Creating a session
B. Using a query string
C. Passing a model
D. Adding a route

13 Which statement correctly describes ViewBag?

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

14 How are values commonly accessed from ViewData?

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

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

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

16 What does session state allow an application to do?

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

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

Working with QueryString Easy
A. Details
B. /Products
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. <section>
B. <table>
C. <form>
D. <script>

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

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

20 Which data annotation marks a model property as mandatory?

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

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. ~/css/site.css
B. ~/Views/css/site.css
C. ~/wwwroot/css/site.css
D. ~/Content/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 AddControllersWithViews() and map a controller route
C. Call AddHttpClient() and map a fallback route
D. Call AddDbContext() and map a health check

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. Store the order in middleware before rendering
B. Query the service directly from the Razor view
C. Pass the order model to a view that renders it
D. Generate all order HTML inside the controller

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 id)
B. IActionResult Details(string action)
C. IActionResult Details(int product)
D. IActionResult Details(int controller)

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 [FromBody] to one and [FromQuery] to the other
B. Apply [Route] to one and [Authorize] to the other
C. Apply [ValidateAntiForgeryToken] to both actions only
D. Apply [HttpGet] to one and [HttpPost] 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. @when (Model.Items.Any()) { <ul>...</ul> }
B. <if test="Model.Items.Any()"><ul>...</ul></if>
C. @{ if Model.Items.Any(): <ul>...</ul> }
D. @if (Model.Items.Any()) { <ul>...</ul> }

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. @Model.Name
B. @ViewData.Name
C. @ViewBag.Name
D. @TempData.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 view renders without using the layout at all
B. The layout automatically loads site.js instead
C. The page renders without content for that section
D. The request fails with a missing-section exception

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. _ViewImports.cshtml
B. _ViewStart.cshtml
C. _ValidationScriptsPartial.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. Store both values in session before returning the view
C. Place both values in separate ViewBag properties
D. Serialize both values into one query parameter

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

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

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. HttpContext.Items
B. ViewData
C. TempData
D. ViewBag

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.Remove("Notice") after reading it
B. Call TempData.Clear() before returning the view
C. Call TempData.ContainsKey("Notice") before reading it
D. Call TempData.Keep("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 MVC and authorization, then call UseAuthorization()
B. Register a distributed cache and session, then call UseSession()
C. Register cookie policy, then call UseCookiePolicy()
D. Register response caching, then call UseResponseCaching()

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(string query, int number)
B. IActionResult Search(string term, int page)
C. IActionResult Search(string id, int index)
D. IActionResult Search(int term, string page)

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-page="Name" />
B. <input asp-action="Name" />
C. <input asp-for="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 an Addresses collection containing no index
B. A model with a City field only in the controller
C. A model with one string property named AddressCity
D. A model with an Address property containing a City property

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 records an error and ModelState becomes invalid
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 skips the action and returns HTTP 404 automatically

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. Check ViewData.Model after saving the data
B. Trust the browser because [Required] blocks every submission
C. Redirect immediately so validation runs on the GET action
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. /Areas/Admin/Reports/Views/Index.cshtml
B. /Views/Admin/Reports/Index.cshtml
C. /Areas/Admin/Views/Reports/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. UseRoutingUseStaticFilesUseAuthorizationUseAuthenticationMapControllerRoute
B. UseStaticFilesUseRoutingUseAuthenticationUseAuthorizationMapControllerRoute
C. UseAuthenticationMapControllerRouteUseRoutingUseAuthorizationUseStaticFiles
D. MapControllerRouteUseRoutingUseAuthenticationUseStaticFilesUseAuthorization

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 when invalid; return the view when valid
B. Redirect to the GET action for both invalid and valid submissions
C. Return the view for both invalid and valid submissions
D. Return the view when invalid; redirect to the GET action 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. Edit(string slug) is selected because route values originate as strings
B. Edit(int id) is selected because 42 converts successfully to an integer
C. Action selection is ambiguous because parameter types do not choose the action
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. @Html.Raw(FormatValue<int>(Model.Count))
B. @FormatValue<int>(Model.Count)
C. @{ FormatValue<int>(Model.Count); }
D. @(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 once at the layout's RenderSectionAsync location
B. The section is rendered where declared inside the content view
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. Only the root file runs for the full view, and _Root also wraps the partial
B. Both files run independently for the full view and partial, producing nested layouts
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. 0, because numeric conversion failure supplies the type default
B. An empty value, because invalid numeric input is discarded
C. abc, because the attempted ModelState value has precedence
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. first | first
B. second | second
C. second | first
D. first | second

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. Only Action A reads the value, and it is removed before 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. Both actions read the value, and it is removed after 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 access is request-locking, so the final counter is guaranteed to become 7
B. Session access is non-locking, so both updates may succeed while one increment is lost
C. Session values are immutable, so neither request can overwrite the stored counter
D. Session values are transactional, so a write conflict automatically retries one request

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. A binding error caused by duplicate keys
B. A single string containing core,mvc
C. An array containing core and mvc
D. An array containing only 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?

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

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 becomes 7, while Name remains unset because the binder chose the Instructor prefix
B. Id remains 0, while Name becomes Ada because unprefixed keys take precedence
C. Both properties remain unset because every query key must use exactly the same prefix
D. Id becomes 7, and Name becomes Ada because prefixed and unprefixed keys are merged

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. Add [ValidateAntiForgeryToken] to the receiving controller action
B. Call ModelState.Clear() immediately before submitting the form
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. Validation succeeds because implicit required validation always permits null values
B. Validation succeeds because only an explicit [Required] attribute triggers validation
C. Binding fails before validation because reference properties cannot receive null
D. Validation fails because a non-nullable reference property is treated as implicitly required

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. Configure an antiforgery header name and copy the hidden token value into that request header
C. Send only the antiforgery cookie because the request cookie alone proves authenticity
D. Copy the hidden token into the JSON model under any property name chosen by the client

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. Cast the object to dynamic so the cookie provider accepts its runtime members
B. Serialize the object to a compact string and deserialize it after retrieval
C. Place the object in ViewData because ViewData automatically survives a redirect
D. Store the object directly because TempData automatically serializes every CLR type

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. The action executes and must always test ModelState.IsValid manually
B. MVC redirects to the same action and stores validation errors in TempData
C. MVC returns an automatic HTTP 400 response before the action body executes
D. The action executes with null and MVC discards all model-state errors

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. Use a shared distributed session cache and share required Data Protection keys
B. Move session middleware after endpoint execution and enable response buffering
C. Store larger objects in each instance's session and disable cookie consent
D. Use separate in-memory caches and increase the session idle timeout