In MVC what is difference between partial view and strongly typed view?

asp.net-mvc

Solution

A partial view is nothing more than a "piece" of Html that you can keep in a separate file that you can reuse in other views. Sort of like UserControls in ASP.NET WebForms.

A Strongly Typed view means it has a ViewModel associated to it that the controller is passing to it and all the elements in that View can use those ViewModel properties

You can have strongly typed partials as well. Meaning that piece of Html needs specific data so you type it to a certain ViewModel

Here is an example of a Strongly Typed View

@model SomeViewModel

...// all the html comes after

A view that is not strongly typed does not have a `@model SomeViewModel` line

Here's an example of a controller action that renders a normal view without a ViewModel

public ActionResult Index() {
    return View();
}

Here's one that renders a strongly typed View

public ActionResult Index() {
    var model = new SomeViewModel();
    return View(model);
}

And the view makes use of that ViewModel by having the `@model SomeViewModel` at the top of the file.

So now that the view has a ViewModel I can display elements that are bound to the ViewModel like

@Html.TextBoxFor(m => m.FirstName)
@Html.CheckBoxFor(m => m.IsAwesome)

So any data entered into those fields are bound to the ViewModel. When the user clicks the submit button, those entered values get sent back to the server.

As I said before, partial view is a reusable piece of Html. So in that same view I can add in my partial. Let's say I have a partial view that contains a standard bit of Html that I want to reuse all over my site, like a Footer

I can create a .cshtml file and put this inside it

<div> footer text here</div>

And then include it on any View, doesn't matter if it's strongly typed or not, it's just reusable Html

@model SomeViewModel

@Html.TextBoxFor(m => m.FirstName)
@Html.CheckBoxFor(m => m.IsAwesome)

{@Html.RenderPartial("MyFooter")}

Problem

Question is the title itself. I am new to MVC and I am now following self learning. Kindly give me answer which is clear for a fresher to MVC. Thanks.

Original source