i just encounter a code where a person showing how to keep webgrid
in partial view and populate. see the link for complete code Bind WebGrid form AJAX
see their partial view code
<!-- Current Buildings -->
@{
if (Model != null && Model.Count() > 0)
{
var grid = new WebGrid(source: Model, rowsPerPage: ThisController.PageSize, ajaxUpdateContainerId: "tabs-2", defaultSort: "BuildingNumber");
grid.Bind(Model, rowCount: Model.Count(), autoSortAndPage: false);
grid.Pager(WebGridPagerModes.All);
grid.GetHtml(
tableStyle: "display",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("BuildingNumber", header: "Building Number"),
grid.Column("ConstructionDate", header: "Construction Date"),
grid.Column("ExtSquareFeet", header: "Exterior Sq. Ft."),
grid.Column("IntSquareFeet", header: "Interior Sq. Ft."),
grid.Column("IU_Avail", header: "IU Available"),
grid.Column("SpaceAvail", header: "Space Available"),
grid.Column("FixedAssetValue", header: "Fixed Asset Value"),
grid.Column("FixedEquipValue", header: "Fixed Equipment Value")
)
);
}
else
{
@:There are no buildings at this facility.
}
}
but there is no reference for model at top like
@model IEnumerable<MyProject.Models.BuildingModel>
see how partial view understand which model they need to use to populate the webgrid.
see this code to bind webgrid
grid.Bind(Model, rowCount: Model.Count(), autoSortAndPage: false);
here the word model has been used so how web grid know about model because no reference has been added at top of partial view.
in main view they use this code to render partial view
@Html.Partial("_Buildings")
i do not know that model data no need to pass with
@Html.Partial("_Buildings")
or model data automatically pass to partial view.
please help me to understand this. thanks