top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How can i create a partial view in MVC and consume it?

+1 vote
263 views
How can i create a partial view in MVC and consume it?
posted May 13, 2014 by Upma

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes

Partial view is a reusable view (like a user control) which can be embedded inside other view. For example let’s say all your pages of your site have a standard structure with left menu, header, and footer as shown in the image below.
MVC

For every page you would like to reuse the left menu, header, and footer controls. So you can go and create partial views for each of these items and then you call that partial view in the main view.

To consume it:
When you add a view to your project you need to check the “Create partial view” check box.
Consume it

Once the partial view is created you can then call the partial view in the main view using the Html.RenderPartial method as shown in the below code snippet:

<body>
<div>
<% Html.RenderPartial("MyView"); %>
</div>
</body> 
answer May 14, 2014 by Tapesh Kulkarni
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...