What exactly is strongly typed View data in Asp.Net MVC?

A strongly typed view in ASP. NET MVC inherits from System.Web.Mvc. ViewPageThis allows intellisense to work in your views See e.

G this tutorial.

A strongly typed view in ASP. NET MVC inherits from System.Web.Mvc. ViewPage and contains a Model property that is of type specified by T.

This allows intellisense to work in your views. See e.g. This tutorial.

Let's say you have a need to display several pieces of loosely related data on a View: Contact Information, Sales Forecasts and Call You could simply just inject these into the ViewData and pull them out and strongly type them from the View, however a better approach would be to create a custom Model which encapsulates each of these. Then you would strongly type the View itself to this custom model. It plays into type safety and makes code-assist more intuitive amongst other benefits such as testability.

Every View has a Model property. To strongly type a View means to make it inherit from some ViewPage, and the Model property becomes the type of T. If you don't strongly type your view, the Model is of type "Object".

Strongly typing your View's model has advantages in that you can directly access the properties of the Model. You get intellisense and compiler checking, instead of relying on using "magic strings" to access a ViewData dictionary - which would break at runtime if your model ever changed. For example, if you had public class Person { public int Age { get; set; } } and you made your View strongly typed on the Person class, you would be able to access Model.

Age from your view templates. If your View was not strongly typed, then Model would have no properties for you to access, and you would have to explicitly cast it to a type or pass your data through a ViewData dictionary. To strongly type this view, you simply make it inherit from ViewPage.

As a strongly typed model object. I’ve written a simple MVC 3 Top Blog application to compare and contrast dynamic and strongly typed views. Right click in the IndexNotStonglyTyped() method and add a Razor view.

Make sure the Create a strongly-typed view box is not checked. Because we’re using a dynamic and not a strongly typed view, intellisense doesn’t help us. Now we’ll add a strongly typed view.

Notice it’s exactly the same return View(topBlogs); call as the non-strongly typed view. Right click inside of StonglyTypedIndex() and select Add View. This time select the Blog Model class and select List as the Scaffold template.

Inside the new view template we get intellisense support. The c# project can be downloaded here.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions