c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
asp.net MVC

What is Partial Views in asp.net MVC ?

| | ASP-NET , CSharp , MVC

In this Article, I describe what is partial view in asp.net mvc. Partial views are used to encapsulate reusable view logic and it simplify the complexity of views. We can use one partial view on multilple views , where we need similar kind of view logics.

 If you create a partial view in shared folder then you can access a partial view anywhere in your application but if you create partial view in specific folder or models with in that folder or modules only you can access your partial views.

 Partial View creation is similar to normal view creation, but check Create as a partial view checkbox before add a partial view.

 Render PartialView

@Html.Partial("Partial viewName",Model)

Example

@Html.Partial("_Product", item)

Here _Product is a Partial view name and item is a name of the model.

_Product View

 ==================

@model MVCApp.Models.Product

<table>

   <tr>

       <td>

            @Model.Name

       </td>

       <td>

            @Model.Description

       </td>

   </tr>

</table>

 

Index View

@model IEnumerable<Gnawazexport.Areas.Admin.Models.ProductImage>

 @{

   ViewBag.Title = "Index";

}

@foreach (var item in Model)

{

@Html.Partial("_Product", item)

}

Description

In this above demonstration, I used product as a partial view and use this partial in index view. Similarly we can use this partial wherever you need.