Reputation: 163
I have 4 views under Views/Shared folder.
Trying to render the 3 views in Main View,but not able to render.Don't know where am doing wrong. Code in Main view to render partial views:
<div id="RenderAttendance">
@Html.Partial("~/Views/Shared/_Attendance.cshtml");
</div>
<div id="RenderLeaves" >
@Html.Partial("~/Views/Shared/_Leaves.cshtml");
</div>
<div id="RenderEfforts" >
@Html.Partial("~/Views/Shared/_Efforts.cshtml");
</div>
Upvotes: 5
Views: 17710
Reputation: 19422
My Partial View was named "Grid" in a folder called "Control" right under the "Views" directory.
I had to use:
@Html.Partial("/Views/Control/Grid")
Once I did this, MVC was able to load it then.
Yes, I realize I should prefix my partial views with an Underscore, but because I organize them all under the "Control" folder, that's my way of denoting their purpose.
As I migrate from Web Forms to MVC, it helps me to think of Partial Views as reusable Custom User Controls I add to Full Page Views.
Upvotes: 1
Reputation: 855
Hai please try like below
<div id="RenderAttendance">
@Html.Partial("_Attendance");
</div>
<div id="RenderLeaves" >
@Html.Partial("_Leaves");
</div>
<div id="RenderEfforts" >
@Html.Partial("_Efforts");
</div>
Note : If your partial views contains a model class means try the below one
<div id="RenderAttendance">
@Html.Partial("_Attendance", new ModelClassName());
</div>
<div id="RenderLeaves" >
@Html.Partial("_Leaves", new ModelClassName_2());
</div>
<div id="RenderEfforts" >
@Html.Partial("_Efforts", new ModelClassName_3());
</div>
Upvotes: 3