Sukesh Marla
Sukesh Marla

Reputation: 177

Asp.Net MVC View function and ViewData

I have a small confusion in Asp.Net MVC

How rendering works in Asp.net MVC? We invoke View function - > Which will find the view and ask ViewEngine to parse it. Because of ViewEngine final outcome is HTML.

1)Whatever ViewData we create its available inside View. My understanding is ViewData and View function both are part of controller base class which makes ViewData available inside View function. Is it correct?

2)Finally Whats the point with WebViewPage class. ViewData keyword we use inside View(.cshtml) page is coming from the WebViewPage class. What role WebViewPage plays here.

I will really appreciate If you can point me with some good resource to understand the same

Upvotes: 0

Views: 399

Answers (2)

Victor C
Victor C

Reputation: 70

Go peek inside he source code that renders the views visit msdn

Upvotes: 0

Judge Bread
Judge Bread

Reputation: 501

1) ViewData is merely a dictionary of objects that you can fill in the Controller and retrieve within the view. Since it is a dictionary of objects you need to cast the data back into the type it was to make full use of it.

2) WebViewPage is the base type of a razor page. It is the defined class which razor pages are compiled into at runtime. The web.config inside the views folder specifies the pageBaseType of the razor pages specifically to WebViewPage. These are two good resources regarding why its use and how you can extend it. Link1 and Link2.

Upvotes: 0

Related Questions