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!

Q91

Q91 What is the role of [Authorize] in ASP.NET MVC?

A

To define routes

B

To restrict access to actions

C

To validate models

D

To render views

Q92

Q92 How can you implement custom authentication in ASP.NET MVC?

A

Create a custom AuthorizeAttribute

B

Use HttpContext.User

C

Modify RouteConfig

D

Customize ViewBag

Q93

Q93 How do you enable client-side validation in ASP.NET MVC?

A

Add @Html.EnableClientValidation()

B

Include jQuery Validation library

C

Define rules in the Controller

D

Both A and B

Q94

Q94 How do you check if a user is authenticated in a Controller?

A

Use HttpContext.IsAuthenticated

B

Use User.Identity.IsAuthenticated

C

Use Session["Authenticated"]

D

Use Authorize.IsValid()

Q95

Q95 How do you validate a model manually in an action?

A

Use TryValidateModel()

B

Call ModelState.Clear()

C

Use ModelState.IsValid

D

Override the Validate method

Q96

Q96 A validation error is not displayed in the view. What could be the issue?

A

Validation scripts are missing

B

Controller is invalid

C

Route is not defined

D

Model is null

Q97

Q97 A [Required] validation is ignored on the server-side. What could be wrong?

A

Model binding failed

B

DataAnnotations namespace is missing

C

Client-side validation is disabled

D

Validation attribute is not applied

Q98

Q98 The [Authorize] attribute is not working as expected. What could be wrong?

A

Custom attribute is not registered

B

Authentication middleware is missing

C

Route is invalid

D

User role is not defined

Q99

Q99 What is Dependency Injection in ASP.NET MVC?

A

A pattern for database access

B

A technique for managing dependencies

C

A routing mechanism

D

A way to validate models

Q100

Q100 Which interface is commonly used for Dependency Injection in ASP.NET MVC?

A

IServiceProvider

B

IDependencyResolver

C

IDisposable

D

IControllerFactory

Q101

Q101 What is the main benefit of using Dependency Injection?

A

Faster execution

B

Loose coupling

C

Improved UI rendering

D

Simpler validation

Q102

Q102 Which lifecycle is associated with a Singleton service in DI?

A

Per request

B

Single instance

C

Per controller

D

Multiple instances

Q103

Q103 How do you configure Dependency Injection in ASP.NET MVC?

A

By defining dependencies in RouteConfig

B

Using an IoC container

C

Adding Razor syntax

D

Using Web.config

Q104

Q104 How do you register a service in an IoC container in ASP.NET MVC?

A

container.Register();

B

container.Add();

C

container.Map();

D

container.Bind();

Q105

Q105 How do you resolve a dependency manually in a controller?

A

Use ResolveDependency()

B

Call DependencyResolver.GetService()

C

Use GetDependency()

D

Call Resolve()

Q106

Q106 How do you inject a dependency using a constructor in MVC?

A

Add it to Global.asax

B

Define it in the controller constructor

C

Use a SetDependency() method

D

Modify the RouteConfig

Q107

Q107 A service is not being resolved by the IoC container. What could be wrong?

A

The service is not registered

B

Controller name is invalid

C

View is missing

D

Route is incorrect

Q108

Q108 A Singleton service creates multiple instances. What could be the issue?

A

Service scope is not Singleton

B

Controller is invalid

C

Incorrect routing

D

Model binding failed

Q109

Q109 An injected service throws a null reference exception. What is the issue?

A

Service is not registered

B

Service is misconfigured

C

Controller constructor is missing

D

Both A and B

Q110

Q110 What is Entity Framework (EF) in ASP.NET MVC?

A

A UI framework

B

A database ORM

C

A routing library

D

A dependency injection tool

Q111

Q111 What is the purpose of DbContext in Entity Framework?

A

Manage database schema

B

Provide a bridge between models and database

C

Define routing

D

Validate data annotations

Q112

Q112 How does Entity Framework handle lazy loading?

A

It loads related data automatically

B

It loads only requested data

C

It fetches all related data upfront

D

It does not support lazy loading

Q113

Q113 What is the difference between DbSet and DbContext in EF?

A

DbSet represents collections, DbContext manages database connections

B

Both are equivalent

C

DbContext defines routing, DbSet validates models

D

DbSet handles DI, DbContext does not

Q114

Q114 Which method is used to configure EF mappings using Fluent API?

A

Configure()

B

OnModelCreating()

C

Map()

D

CreateMapping()

Q115

Q115 How do you retrieve all records from a table using Entity Framework?

A

db.TableName.ToList()

B

db.GetAll("TableName")

C

db.TableName.Get()

D

db.FetchAll("TableName")

Q116

Q116 How do you include related entities in a query using EF?

A

Use Include() method

B

Use Join() method

C

Add a new DbSet

D

Use eager loading

Q117

Q117 How do you add a new record to a table using EF?

A

db.Add()

B

db.TableName.Add(entity)

C

db.SaveChanges(entity)

D

db.New(entity)

Q118

Q118 A query using Entity Framework returns no results. What could be wrong?

A

Invalid connection string

B

Lazy loading is disabled

C

DbContext is not disposed

D

Primary key is missing

Q119

Q119 A DbContext instance throws a "disposed" exception. What is the issue?

A

It is being used after being disposed

B

Connection string is invalid

C

Entity model is not defined

D

Primary key is missing

Q120

Q120 What is the purpose of AJAX in ASP.NET MVC?

A

Handle routing

B

Update parts of a page asynchronously

C

Manage database connections

D

Render Razor views