How to pass Model to Partial View in ASP.NET MVC?


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


Asked by:- neena
0
: 6950 At:- 6/5/2020 3:44:34 PM
ASP.NET MVC C# Model to Partial View







1 Answers
profileImage Answered by:- vikas_jk

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"} })
1
At:- 6/5/2020 3:58:01 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use