I have created Bootstrap tabs inside ASP.NET MVC razor view and calling Partial View from inside bootstrap, but I would like to know how can I pass Model to partial view while rendering it?
@Html.Partial("~/Views/Home/_PartialView.cshtml")
I would also like to pass ViewData, if possible.Thanks
You can simply pass model like
@Html.Partial("~/Views/Home/_PartialView.cshtml",Model)
Inside your Partial view, you can get Model values like you usually do in any View
Suppose _PartialView.cshtml
looks like this
@model ProjectName.Model
<div>
@Model.PropertyValue
</div>
If you want to pass model with View data to partial view, just add viewdata after Model
@Html.Partial("~/Views/Home/_PartialView.cshtml",Model, new ViewDataDictionary { { "ViewDataName", "ViewDataValue"} })
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly