an HCL GUVI product

ASP.NET MVC MCQ Banner

ASP.NET MVC Multiple Choice Questions (MCQs) and Answers

Master ASP.NET MVC with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of ASP.NET MVC concepts. Begin your placement preparation journey now!

Q121

Q121 Which library is commonly used for AJAX in ASP.NET MVC?

A

jQuery

B

Angular

C

React

D

Knockout

Q122

Q122 What is a Partial View in ASP.NET MVC?

A

A fully rendered view

B

A reusable view component

C

A controller action

D

A database entity

Q123

Q123 How is a Partial View rendered using HTML Helpers?

A

@Html.RenderPartial("ViewName")

B

@Html.Render("ViewName")

C

@Html.Partial("ViewName")

D

@Html.View("ViewName")

Q124

Q124 What is the role of JsonResult in AJAX requests?

A

Return HTML

B

Return JSON data

C

Handle routing

D

Define models

Q125

Q125 How do you make an AJAX GET request using jQuery?

A

$.ajax({type: "GET"})

B

$.get("url")

C

$.ajaxGet("url")

D

$.fetch("url")

Q126

Q126 How do you update a DOM element with data from an AJAX call?

A

Use append()

B

Use load()

C

Use update()

D

Use replace()

Q127

Q127 How do you send data in an AJAX POST request using jQuery?

A

$.ajax({type: "POST", data: data})

B

$.post("url")

C

$.ajaxPost("url")

D

$.fetchPost("url")

Q128

Q128 An AJAX request returns a 404 error. What could be the issue?

A

Invalid URL

B

Missing controller

C

Incorrect data format

D

View not found

Q129

Q129 A Partial View does not render correctly. What could be wrong?

A

View is missing

B

Invalid route

C

Incorrect model passed

D

All of the above

Q130

Q130 What is the purpose of the [Authorize] attribute in ASP.NET MVC?

A

Restrict access to routes

B

Enable authentication

C

Handle model validation

D

Secure Razor views

Q131

Q131 What is Cross-Site Request Forgery (CSRF)?

A

A database attack

B

A form of XSS attack

C

An attack where unauthorized commands are performed on behalf of a user

D

A form validation error

Q132

Q132 How do Anti-Forgery tokens protect against CSRF attacks in ASP.NET MVC?

A

They encrypt sensitive data

B

They validate user identity

C

They ensure that a form request is from the authenticated user

D

They block unauthorized access

Q133

Q133 What is the purpose of HTTPS in ASP.NET MVC applications?

A

To optimize routing

B

To secure data in transit

C

To restrict controller access

D

To simplify model binding

Q134

Q134 How do you enable Anti-Forgery tokens in a Razor view?

A

@Html.EnableAntiForgeryToken()

B

@Html.AntiForgeryToken()

C

@Html.AddCSRF()

D

@Html.EnableCSRF()

Q135

Q135 How do you implement custom role-based authorization in ASP.NET MVC?

A

Create a custom AuthorizeAttribute

B

Add roles in Web.config

C

Use HttpContext.SetRole()

D

Modify RouteConfig

Q136

Q136 How do you enforce HTTPS for a controller in ASP.NET MVC?

A

Use the [HttpsRequired] attribute

B

Use the [RequireHttps] attribute

C

Define HTTPS in RouteConfig

D

Set HTTPS in Web.config

Q137

Q137 A [RequireHttps] attribute throws an error on localhost. What is the issue?

A

HTTPS is not enabled

B

Route is missing

C

Anti-Forgery token is missing

D

Certificate is invalid

Q138

Q138 An Anti-Forgery token validation fails. What could be the issue?

A

Token mismatch

B

Route conflict

C

Controller is missing

D

Invalid Razor syntax

Q139

Q139 What is bundling in ASP.NET MVC?

A

Combining multiple scripts or stylesheets into a single bundle

B

Caching views

C

Minimizing routing

D

Combining models

Q140

Q140 How does caching improve performance in ASP.NET MVC?

A

By storing frequently used data

B

By validating model bindings

C

By optimizing Razor syntax

D

By managing routes dynamically

Q141

Q141 What is output caching in ASP.NET MVC?

A

Storing HTML responses for reuse

B

Caching database queries

C

Caching controller actions

D

Storing Razor syntax

Q142

Q142 How do you enable output caching for an action in ASP.NET MVC?

A

Use the [Cache] attribute

B

Use the [OutputCache] attribute

C

Define caching in Web.config

D

Set caching in RouteConfig

Q143

Q143 How do you implement bundling in ASP.NET MVC?

A

Add bundles in the BundleConfig.cs file

B

Define bundles in RouteConfig

C

Use the @Html.Bundle() method

D

Add bundles in the controller

Q144

Q144 Bundling is not working in production. What could be the issue?

A

Minification is disabled

B

Debug mode is enabled

C

BundleConfig is missing

D

All of the above

Q145

Q145 Cached data is not being updated after changes. What could be the issue?

A

Cache duration is too long

B

Controller action is missing

C

OutputCache is invalid

D

BundleConfig is incorrect

Q146

Q146 What is the purpose of unit testing in ASP.NET MVC?

A

Test database performance

B

Test individual components

C

Test Razor syntax

D

Test server configurations

Q147

Q147 How does Dependency Injection improve testability in ASP.NET MVC?

A

By enabling the use of mocks

B

By reducing database calls

C

By optimizing routes

D

By simplifying view rendering

Q148

Q148 What is the role of a mocking framework in unit testing?

A

It handles routing

B

It creates fake dependencies

C

It validates Razor syntax

D

It simplifies model binding

Q149

Q149 How do you test a controller action using NUnit?

A

Create a mock HttpContext

B

Call the action directly and assert the result

C

Use RouteConfig to define the test

D

Create a Razor view for testing

Q150

Q150 How do you mock a DbContext for unit testing?

A

Use InMemoryDatabase

B

Use a mocking library

C

Manually create stubs

D

Both A and B