asp.net mvc - In MVC what is difference between partial view and strongly typed view? -
question title itself. new mvc , following self learning. kindly give me answer clear fresher mvc. thanks.
a partial view nothing more "piece" of html can keep in separate file can reuse in other views. sort of usercontrols in asp.net webforms.
a typed view means has viewmodel associated controller passing , elements in view can use viewmodel properties
you can have typed partials well. meaning piece of html needs specific data type viewmodel
here example of typed view
@model someviewmodel ...// html comes after
a view not typed not have @model someviewmodel
line
here's example of controller action renders normal view without viewmodel
public actionresult index() { return view(); }
here's 1 renders typed view
public actionresult index() { var model = new someviewmodel(); return view(model); }
and view makes use of viewmodel having @model someviewmodel
@ top of file.
so view has viewmodel can display elements bound viewmodel like
@html.textboxfor(m => m.firstname) @html.checkboxfor(m => m.isawesome)
so data entered fields bound viewmodel. when user clicks submit button, entered values sent server.
as said before, partial view reusable piece of html. in same view can add in partial. let's have partial view contains standard bit of html want reuse on site, footer
i can create .cshtml file , put inside it
<div> footer text here</div>
and include on view, doesn't matter if it's typed or not, it's reusable html
@model someviewmodel @html.textboxfor(m => m.firstname) @html.checkboxfor(m => m.isawesome) {@html.renderpartial("myfooter")}
Comments
Post a Comment