[go: up one dir, main page]

0% found this document useful (0 votes)
9 views1 page

MVC Tricky Questions

The document explains how to use TempData, ViewBag, and ViewData in MVC, highlighting their differences in data access methods. It also describes the four types of filters in MVC, including Action Filters and their application levels. Additionally, it provides optimization tips for stored procedures in SQL, such as using SET NOCOUNT ON and avoiding cursors.

Uploaded by

Suraj Javarat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

MVC Tricky Questions

The document explains how to use TempData, ViewBag, and ViewData in MVC, highlighting their differences in data access methods. It also describes the four types of filters in MVC, including Action Filters and their application levels. Additionally, it provides optimization tips for stored procedures in SQL, such as using SET NOCOUNT ON and avoiding cursors.

Uploaded by

Suraj Javarat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

MVC

1. How to work tempdata in mvc?


-
TempData store objects in the Session just for the next request.
One use case is to pass data to the next request and redirect the current request
to another action.

2. How to work viewbag in mvc?


-
It is type of Dynamic object, that means you can add new fields to viewbag
dynamically and access these fields in the View.

3. How to work viewdata in mvc?


-
The main difference between those two is the way you are accessing the data.
In ViewBag you are accessing data using string as keys - ViewBag[�numbers�] In
ViewData you are accessing data using properties - ViewData.numbers.

4. Filters in MVC?
-
In Mvc having 4 types of filter
1. Action Filter - It is use to execute the filter logic either before action
method execution and after action method execution.
- Customer action filter - it will inherit from ActionFilterAttribute class and
also implement IActionFilter interface.
1. OnActionExecuting - It is called just before the action method is to going call.
It means before renedering the view.
2. OnActionExecuted - It is called just after the action method to going call. It
means after renedering the view.

Action Filter:
Action filter are the custom class that allows to inject pre or post processing
logic before the action method gets executed.
Action filter can be applied globally, controller level and action method level.
Action filters can be created by inheritance a class with �actionfilterattribute�
and can override any of action methods.

1. Authorization filters
2. Action filters
3. Result filters
4. Exception filters

SQL

How to optimize the store procedure?


-
1. use SET NOCOUNT ON for debugging for more information.
2. use the schema name with the object name.
3. do not use prefix in the store procedure name.
4. use if exists of (select 1) insted of (select *)
5. try to avoid using sql server cursor.
6. use transaction as short as posible.
7. use try catch for handling exception.

You might also like