Data Passing Techniques - ViewBag, ViewData and TempData
Easy
A.ViewData
B.TempData
C.SessionState
D.ViewBag
Correct Answer: ViewBag
Explanation:
ViewBag provides a dynamic way to pass data from a controller to a view.
Incorrect! Try again.
13Which technique is commonly used to pass data from one request to the next request?
Data Passing Techniques - ViewBag, ViewData and TempData
Easy
A.ViewData
B.ViewBag
C.LocalData
D.TempData
Correct Answer: TempData
Explanation:
TempData is designed to keep data available for a subsequent request, often after a redirect.
Incorrect! Try again.
14What does a model usually represent in an MVC application?
Models
Easy
A.The page color scheme
B.The browser address bar
C.Application data and rules
D.The server's power supply
Correct Answer: Application data and rules
Explanation:
A model represents data and may contain rules or logic related to that data.
Incorrect! Try again.
15What is session state used for?
Session and State Management
Easy
A.Designing page icons
B.Storing user-specific data
C.Compiling Razor files
D.Creating HTML comments
Correct Answer: Storing user-specific data
Explanation:
Session state stores temporary data associated with a particular user's interaction with an application.
Incorrect! Try again.
16Which HTML element is used to create a form?
ASP.NET Core Forms
Easy
A.<section>
B.<header>
C.<form>
D.<table>
Correct Answer: <form>
Explanation:
The <form> element groups input controls and submits user-entered data.
Incorrect! Try again.
17What does model binding do in ASP.NET Core MVC?
Model Binding
Easy
A.Maps request data to model objects
B.Maps CSS rules to images
C.Maps routes to file folders
D.Maps views to database servers
Correct Answer: Maps request data to model objects
Explanation:
Model binding converts values from a request into action parameters or model properties.
Incorrect! Try again.
18What is the purpose of Tag Helpers in Razor views?
Tag Helpers
Easy
A.To create operating system drivers
B.To encrypt all browser history
C.To replace the application database
D.To add server-side behavior to HTML elements
Correct Answer: To add server-side behavior to HTML elements
Explanation:
Tag Helpers help generate or modify HTML elements using server-side logic.
Incorrect! Try again.
19Where does server-side validation take place?
Server-Side Form Validations
Easy
A.Inside the keyboard
B.Inside the monitor
C.On the web server
D.Only in the browser
Correct Answer: On the web server
Explanation:
Server-side validation checks submitted data on the server before processing it.
Incorrect! Try again.
20Where does client-side validation usually take place?
Client-Side Form Validations
Easy
A.On the web server only
B.In the database engine
C.In the user's browser
D.Inside the file system
Correct Answer: In the user's browser
Explanation:
Client-side validation runs in the browser and can provide immediate feedback before submission.
Incorrect! Try again.
21You are creating an ASP.NET Core web application that must serve HTML pages, process form submissions, and access services through dependency injection. Which project type is the most appropriate starting point?
Building Web Applications using ASP.NET Core
Medium
A.Windows Forms application with controllers
B.ASP.NET Core MVC web application
C.Class library with Razor files
D.Console application with HTTP listeners
Correct Answer: ASP.NET Core MVC web application
Explanation:
An ASP.NET Core MVC web application provides built-in support for controllers, Razor views, routing, middleware, and dependency injection.
Incorrect! Try again.
22In an MVC application, a controller receives a request, retrieves customer data, and returns a page displaying that data. Which sequence best represents the communication flow?
MVC Architecture and Model-View-Controller Communication
Medium
A.View → Model → Controller → Browser
B.Model → Browser → View → Controller
C.Browser → Controller → Model → View
D.Controller → Browser → View → Model
Correct Answer: Browser → Controller → Model → View
Explanation:
The browser sends a request to the controller. The controller works with the model, then passes the result to a view for rendering.
Incorrect! Try again.
23An action must return a 404 Not Found response when a requested product does not exist. Which return statement is most suitable?
Handling Requests and Responses
Medium
A.return NotFound();
B.return RedirectToAction("Index");
C.return BadRequest();
D.return View(product);
Correct Answer: return NotFound();
Explanation:
NotFound() creates an HTTP 404 response, which correctly indicates that the requested resource could not be found.
Incorrect! Try again.
24A controller contains the following action: public IActionResult Details(int id). A request is sent to /Products/Details/12. Assuming conventional routing, what value is assigned to id?
Controllers and Actions
Medium
A.12
B.The value of the controller name
C.The string "Details"
D.0
Correct Answer: 12
Explanation:
Conventional routing maps the third URL segment to the action parameter named id, so the value is converted to the integer 12.
Incorrect! Try again.
25Inside a Razor view, which syntax correctly displays the Name property of a model object?
Razor View Engine and Razor Syntax
Medium
A.{{ Model.Name }}
B.@Model.Name
C.#Model.Name
D.<% Model.Name %>
Correct Answer: @Model.Name
Explanation:
Razor uses the @ symbol to transition from HTML markup to C# expressions, so @Model.Name renders the property value.
Incorrect! Try again.
26A Razor view should display a paragraph only when Model.IsActive is true. Which code is correct?
Razor supports standard C# control statements such as if, allowing markup to be conditionally rendered.
Incorrect! Try again.
27A layout contains @RenderSection("Scripts", required: false). What happens when a child view does not define a Scripts section?
Layouts, Sections and View Start
Medium
A.The child view is rendered twice
B.The layout is skipped for that view
C.The section is ignored without an error
D.The application always throws an exception
Correct Answer: The section is ignored without an error
Explanation:
Setting required to false makes the section optional, so the layout renders successfully when the child view does not define it.
Incorrect! Try again.
28A developer wants every Razor view in a folder and its subfolders to use the same layout without repeating Layout = ... in each view. Which file is intended for this configuration?
Layouts, Sections and View Start
Medium
A.Program.cshtml
B._ViewStart.cshtml
C._ViewImports.cshtml
D._LayoutConfig.cshtml
Correct Answer: _ViewStart.cshtml
Explanation:
_ViewStart.cshtml contains Razor code that runs before views in its folder hierarchy and is commonly used to set a shared layout.
Incorrect! Try again.
29A controller redirects from one action to another and must display a one-time confirmation message after the redirect. Which data-passing mechanism is most appropriate?
Data Passing Techniques - ViewBag, ViewData and TempData
Medium
A.ViewBag
B.TempData
C.A private controller field
D.ViewData
Correct Answer: TempData
Explanation:
TempData is designed to preserve data between requests, including redirects, and is commonly used for one-time messages.
Incorrect! Try again.
30Which statement correctly describes the relationship between ViewBag and ViewData in ASP.NET Core MVC?
Data Passing Techniques - ViewBag, ViewData and TempData
Medium
A.ViewData can only pass data to layouts
B.ViewBag persists data across redirects
C.They use completely separate storage systems
D.ViewBag is a dynamic wrapper around ViewData
Correct Answer: ViewBag is a dynamic wrapper around ViewData
Explanation:
ViewBag provides dynamic access to the same underlying data dictionary used by ViewData; neither is intended to persist data across redirects.
Incorrect! Try again.
31A form collects fields from a database entity but should not allow users to submit properties such as IsAdmin or CreatedDate. Which modeling approach is safest?
Models
Medium
A.Make restricted properties hidden inputs
B.Use a dedicated view model
C.Bind the complete entity directly
D.Store all fields in ViewBag
Correct Answer: Use a dedicated view model
Explanation:
A dedicated view model exposes only fields intended for the form, reducing overposting risks and separating UI requirements from persistence entities.
Incorrect! Try again.
32An ASP.NET Core application needs to store a small shopping-cart identifier for a user across multiple requests. Which configuration is required before using HttpContext.Session?
Session and State Management
Medium
A.Place the value in the response body
B.Only enable endpoint routing
C.Add a second MVC controller
D.Register and configure a distributed cache
Correct Answer: Register and configure a distributed cache
Explanation:
Session state requires a backing cache, such as memory or distributed cache, along with session services and session middleware.
Incorrect! Try again.
33A form submits data to an action that creates a new record. Which pair of attributes is normally used to distinguish the display form action from the processing action?
ASP.NET Core Forms
Medium
A.[HttpPost] for display and [HttpGet] for processing
B.[Route] for display and [Authorize] for processing
C.[HttpPut] for display and [HttpDelete] for processing
D.[HttpGet] for display and [HttpPost] for processing
Correct Answer: [HttpGet] for display and [HttpPost] for processing
Explanation:
GET is conventionally used to display the form, while POST is used to submit and process the entered values.
Incorrect! Try again.
34An action has the signature public IActionResult Search(string category, int page = 1). A request is sent to /Products/Search?category=Books&page=3. What values are bound to the parameters?
Model Binding
Medium
A.category is Books and page is 3
B.category is Search and page is Products
C.category is 3 and page is Books
D.category is null and page is 1
Correct Answer: category is Books and page is 3
Explanation:
Model binding reads matching query-string keys and converts their values to the action parameter types.
Incorrect! Try again.
35A form contains an input named Email, and the action parameter is string email. What allows ASP.NET Core model binding to associate the input with the parameter?
Model Binding
Medium
A.The controller class name supplies the match
B.Matching names are used during binding
C.The browser automatically calls the model constructor
D.Only parameter order is considered
Correct Answer: Matching names are used during binding
Explanation:
Model binding commonly matches submitted field names with action parameter names or model property names, generally without case sensitivity.
Incorrect! Try again.
36A Razor form uses <input asp-for="Email" />. What is a primary benefit of the asp-for Tag Helper?
Tag Helpers
Medium
A.It generates markup connected to the model property
B.It creates a database table for Email
C.It redirects the request to an Email action
D.It disables server-side validation
Correct Answer: It generates markup connected to the model property
Explanation:
The asp-for Tag Helper generates appropriate HTML attributes such as name, id, and validation metadata from the model property.
Incorrect! Try again.
37A developer wants a link to call the Details action of the Products controller with id equal to 8. Which Tag Helper usage is correct?
asp-controller and asp-action identify the endpoint, while asp-route-id supplies the route value for the id parameter.
Incorrect! Try again.
38After submitting a model with a required property left empty, which check should a controller perform before saving the data?
Server-Side Form Validations
Medium
A.Response.HasStarted
B.User.Identity.IsAuthenticated only
C.Request.HasFormContentType only
D.ModelState.IsValid
Correct Answer: ModelState.IsValid
Explanation:
ModelState.IsValid indicates whether model binding and server-side validation succeeded. The controller should usually redisplay the form when it is false.
Incorrect! Try again.
39A model property has the attribute [StringLength(20, MinimumLength = 5)]. Which input satisfies this validation rule?
Server-Side Form Validations
Medium
A.A four-character value
B.A twenty-one-character value
C.A five-character value
D.An empty value without other attributes
Correct Answer: A five-character value
Explanation:
The attribute requires the string length to be at least 5 characters and no more than 20 characters.
Incorrect! Try again.
40A form uses validation attributes and Tag Helpers, but validation messages do not appear until the form is submitted to the server. Which missing component is the most likely cause?
Client-Side Form Validations
Medium
A.The controller constructor
B.The jQuery Validation scripts
C.The database connection string
D.The session middleware
Correct Answer: The jQuery Validation scripts
Explanation:
Client-side validation commonly depends on jQuery Validation and unobtrusive validation scripts being loaded in the page.
Incorrect! Try again.
41An ASP.NET Core application must serve MVC pages, JSON APIs, and static files. Which middleware and endpoint configuration best preserves conventional MVC routing while allowing all three workloads?
Building Web Applications using ASP.NET Core
Hard
A.Use only MapControllers because MVC views and static files are discovered automatically.
B.Use UseStaticFiles, UseRouting, UseAuthorization, and MapControllerRoute with a conventional pattern.
C.Use UseRouting, UseEndpoints, and register static files inside the MVC controller pipeline.
D.Use UseMvc after UseAuthorization and omit endpoint mapping in the application.
Correct Answer: Use UseStaticFiles, UseRouting, UseAuthorization, and MapControllerRoute with a conventional pattern.
Explanation:
Static files need UseStaticFiles, request matching needs routing, authorization should run after routing, and conventional MVC actions require an endpoint route such as MapControllerRoute.
Incorrect! Try again.
42A controller receives an entity from a repository, but the view must display calculated totals and omit internal fields. Which design most appropriately preserves MVC responsibilities?
MVC Architecture and Model-View-Controller Communication
Hard
A.Store the entity in TempData and reconstruct the display model in the view.
B.Project the entity into a dedicated view model in the controller or application layer.
C.Pass the entity directly and calculate totals inside the Razor view.
D.Add presentation-only properties to the database entity and bind the view to it.
Correct Answer: Project the entity into a dedicated view model in the controller or application layer.
Explanation:
A dedicated view model controls the data exposed to the view and keeps presentation calculations and shaping outside the persistence entity and Razor markup.
Incorrect! Try again.
43A POST action successfully creates a resource and must prevent duplicate submission when the user refreshes the browser. Which response pattern is most appropriate?
Handling Requests and Responses
Hard
A.Return NotFound so the browser cannot repeat the request.
B.Return the same view with status code 200 OK.
C.Return RedirectToAction to the resource or confirmation page.
D.Return View with the submitted model and status code 201 Created.
Correct Answer: Return RedirectToAction to the resource or confirmation page.
Explanation:
The Post-Redirect-Get pattern makes the subsequent browser refresh repeat a GET rather than the original POST, reducing accidental duplicate submissions.
Incorrect! Try again.
44An action returns BadRequest() for malformed input, Unauthorized() for an unauthenticated request, and Forbid() for an authenticated user lacking permission. Which interpretation is correct?
Handling Requests and Responses
Hard
A.Forbid redirects every user to the login page.
B.BadRequest indicates invalid request syntax or input.
C.Unauthorized means authenticated but missing a required role.
D.Forbid means the request body could not be parsed.
Correct Answer: BadRequest indicates invalid request syntax or input.
Explanation:
BadRequest represents a client request the server cannot process. Unauthorized generally indicates missing authentication, while Forbid indicates insufficient authorization.
Incorrect! Try again.
45Two actions in the same controller are named Search, one accepting string term and one accepting int id. Requests to /Products/Search?value=12 produce an ambiguous action error. Why?
Controllers and Actions
Hard
A.Action selection does not use arbitrary parameter types as a reliable overload discriminator.
B.Query-string values are always converted to strings before action selection.
C.The controller cannot contain two actions with the same method name.
D.The Search route is reserved for API controllers only.
Correct Answer: Action selection does not use arbitrary parameter types as a reliable overload discriminator.
Explanation:
MVC action selection primarily uses route templates, HTTP verbs, names, and constraints. CLR parameter-type overloads do not reliably distinguish actions.
Incorrect! Try again.
46A controller action accepts a complex parameter named order, and the request contains order.Customer.Name=Lee. What does successful model binding generally require?
Controllers and Actions
Hard
A.The model must inherit from ControllerBase.
B.The action parameter must be decorated with [FromRoute].
C.The request must contain JSON because complex types ignore form keys.
D.The binder must find a compatible value provider and writable nested properties.
Correct Answer: The binder must find a compatible value provider and writable nested properties.
Explanation:
Model binding combines values from configured providers such as form, route, query, and body sources and assigns them to compatible writable properties.
Incorrect! Try again.
47In a Razor view, @Model.Name is rendered as HTML-encoded text, while @Html.Raw(Model.Name) renders markup contained in the value. Which security conclusion is correct?
Razor View Engine and Razor Syntax
Hard
A.Html.Raw prevents XSS by converting markup into text before rendering.
B.Both expressions encode markup because Razor always sanitizes strings.
C.Html.Raw should be used only when the content is trusted or safely sanitized.
D.Model.Name is unsafe because Razor encoding is disabled for model properties.
Correct Answer: Html.Raw should be used only when the content is trusted or safely sanitized.
Explanation:
Razor HTML-encodes ordinary string output, but Html.Raw bypasses encoding and can expose the application to XSS when content is untrusted.
Incorrect! Try again.
48A Razor loop contains @if (item.IsActive) { <span>Active</span> }. The markup is emitted only for active items. Which Razor behavior explains this?
Razor View Engine and Razor Syntax
Hard
A.Razor switches between code and markup contexts based on syntax boundaries.
B.Razor treats all markup inside code blocks as literal C# strings.
C.The view engine replaces conditional markup with a client-side script.
D.The compiler executes HTML before evaluating the if expression.
Correct Answer: Razor switches between code and markup contexts based on syntax boundaries.
Explanation:
Razor integrates C# and markup in one template and determines context from transitions such as braces and HTML tags.
Incorrect! Try again.
49A shared _ViewStart.cshtml sets Layout = "_MainLayout", but one view must use a different layout. What is the correct approach?
Layouts, Sections and View Start
Hard
A.Define a second @section Layout inside the view.
B.Change _ViewImports.cshtml because it overrides layout inheritance.
C.Use ViewData to replace the layout after the view begins rendering.
D.Set the alternative Layout value in the view itself.
Correct Answer: Set the alternative Layout value in the view itself.
Explanation:
A view can override the layout inherited from _ViewStart.cshtml by assigning its own Layout property.
Incorrect! Try again.
50A layout declares @RenderSection("Scripts", required: true). A view does not define that section, and no fallback is provided. What is the result?
Layouts, Sections and View Start
Hard
A.The layout silently renders an empty section.
B.The section is automatically populated from _ViewImports.cshtml.
C.Rendering fails because the required section is missing.
D.The view renders, but scripts move to the document head.
Correct Answer: Rendering fails because the required section is missing.
Explanation:
A required section must be defined by the rendered view. Otherwise, Razor raises an error during view rendering.
Incorrect! Try again.
51A controller assigns ViewData["Notice"] = "Saved" and returns a view. The view reads ViewBag.Notice. What is expected?
Data Passing Techniques - ViewBag, ViewData and TempData
Hard
A.The value is available because ViewBag and ViewData share the same underlying dictionary.
B.The value is unavailable because ViewBag works only with controller properties.
C.The value is converted to JSON before ViewBag can read it.
D.The value survives a redirect because all view data is session-backed.
Correct Answer: The value is available because ViewBag and ViewData share the same underlying dictionary.
Explanation:
ViewBag is a dynamic wrapper over ViewData, so values written through one mechanism can be read through the other during the same request.
Incorrect! Try again.
52A POST action sets TempData["Message"] and redirects to a GET action. The GET reads the message once and renders a view. What is the typical behavior?
Data Passing Techniques - ViewBag, ViewData and TempData
Hard
A.The message remains permanently until the application restarts.
B.The message is unavailable because redirects clear controller state.
C.The message is available only if it is also copied into ViewBag.
D.The message is available during the next request and usually removed after it is read.
Correct Answer: The message is available during the next request and usually removed after it is read.
Explanation:
TempData is designed for short-lived data across requests, especially redirects. Reading it typically marks the entry for deletion.
Incorrect! Try again.
53A domain model has a calculated Total property with only a getter, while a posted form contains a Total field supplied by the client. What is the safest design?
Models
Hard
A.Make Total writable so the default binder can populate it.
B.Bind directly to the domain model and trust the posted total.
C.Recalculate Total on the server from trusted posted inputs.
D.Store the posted total in ViewBag and use it during persistence.
Correct Answer: Recalculate Total on the server from trusted posted inputs.
Explanation:
Client-submitted calculated values are untrusted. The server should bind only permitted inputs and derive authoritative values itself.
Incorrect! Try again.
54An application uses session state in a multi-instance deployment. Users intermittently lose session values after requests are routed to different instances. Which solution addresses the underlying problem?
Session and State Management
Hard
A.Store session values in ViewData so they become instance independent.
B.Increase the controller action timeout to preserve session affinity.
C.Enable session middleware without changing the deployment.
D.Use a distributed session store shared by all application instances.
Correct Answer: Use a distributed session store shared by all application instances.
Explanation:
In a scaled deployment, session data must be available to every instance. A shared distributed cache provides consistent session storage.
Incorrect! Try again.
55A developer stores a large object graph in ASP.NET Core session and observes serialization overhead and stale values across requests. Which change is most appropriate?
Session and State Management
Hard
A.Copy the entire object graph into TempData on every request.
B.Store only small identifiers or essential state and reload current data.
C.Disable cookies so session values are reconstructed automatically.
D.Use session as the primary database for the object graph.
Correct Answer: Store only small identifiers or essential state and reload current data.
Explanation:
Session is intended for limited user-specific state. Persisting identifiers and retrieving current data reduces serialization cost and stale-state risks.
Incorrect! Try again.
56A Razor form submits a POST request to an action protected by antiforgery validation. The form was generated with the Form Tag Helper. What must normally be present for validation to succeed?
ASP.NET Core Forms
Hard
A.Only a query-string token appended to the form action.
B.A manually added Authorization header containing the user password.
C.A session value named __RequestVerificationToken only.
D.The antiforgery token generated by the form plus the associated request cookie.
Correct Answer: The antiforgery token generated by the form plus the associated request cookie.
Explanation:
The Form Tag Helper normally emits a hidden antiforgery field for unsafe methods, and validation compares it with the corresponding antiforgery cookie.
Incorrect! Try again.
57An action has [HttpPost] public IActionResult Save([Bind("Name,Price")] Product product). The posted form also includes IsAdmin=true. What happens to IsAdmin during binding?
Model Binding
Hard
A.It is bound only when the request is sent as JSON.
B.It is ignored because it is excluded by the bind include list.
C.It is bound and then overwritten by the database automatically.
D.It causes model binding to fail for the entire product.
Correct Answer: It is ignored because it is excluded by the bind include list.
Explanation:
The include list restricts binding to Name and Price. This helps prevent overposting of properties such as authorization-related flags.
Incorrect! Try again.
58A form posts Items[0].Name, Items[2].Name, and Items[3].Name, omitting index 1. Under indexed collection binding conventions, what issue can occur?
Model Binding
Hard
A.The binder converts all item names into a single comma-separated string.
B.The request is rejected before model validation runs.
C.The binder always creates four objects and leaves index 1 empty.
D.Binding may stop at the gap, so later items may not bind as expected.
Correct Answer: Binding may stop at the gap, so later items may not bind as expected.
Explanation:
Sequential numeric indexes are expected for many collection-binding patterns. A gap can cause the binder to stop processing subsequent indexed elements.
Incorrect! Try again.
59A form uses <input asp-for="Email" /> and the model state contains an invalid submitted value. The model property has a different value set by the controller before returning the view. Which value is typically rendered?
Tag Helpers
Hard
A.The Tag Helper reads only the database value and ignores both sources.
B.The value from model state typically takes precedence over the model property.
C.The input is left empty whenever model validation fails.
D.The controller's model property always takes precedence.
Correct Answer: The value from model state typically takes precedence over the model property.
Explanation:
Input Tag Helpers use attempted values retained in ModelState, allowing users to see and correct their submitted input after validation errors.
Incorrect! Try again.
60A POST action checks ModelState.IsValid, but a malicious client submits an invalid date string. Why must the action still perform this check before using the model?
Server-Side Form Validations
Hard
A.The browser guarantees valid values for every submitted form field.
B.Data annotations execute only after the action returns a view.
C.Binding conversion errors are recorded in ModelState even when attributes are absent.
D.Invalid values are silently converted to secure defaults by the framework.
Correct Answer: Binding conversion errors are recorded in ModelState even when attributes are absent.
Explanation:
Model binding records conversion and format errors in ModelState. The action must check validity before relying on the bound values.
Incorrect! Try again.
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 →