-->

Part 17 - What is Partial View in Asp.net MVC




What is Partial View?
        The partial view is the reusable view .It can reduce duplication of view content and allow view elements to be reused.Partial views also have the .cshtml extension
How to call a partial view
@Html.Partial(“PartialViewName”, new { id = 1} );
@{ Html.RenderPartial(“PartialViewName”, viewModel);}
@{ Html.RenderAction(“Method", "Controller”, customViewData);}

Example 

Baca Juga



#Partial View - (Partial1.cshtml)

<div>
<h3>I am in Partial 1</h3>
</div>
  
#Controller code - TestController


using MVCTutorial.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;

namespace MVCTutorial.Controllers
{
public class TestController : Controller
{

public ActionResult Index()
{

return View();
}


public ActionResult ShowPartial()
{

return PartialView("Partial1");
}

}
}

 # View Page- (Index.cshtml)


@{
ViewBag.Title = "Index";
Layout = null;
}

<div class="container" style="width:40%;margin-top:2%">
@Html.Partial("Partial1", new { id = 1} );
@{ Html.RenderPartial("Partial1");}
@{ Html.RenderAction("ShowPartial");}
</div>

     

Related Posts

0 Response to "Part 17 - What is Partial View in Asp.net MVC"

Post a Comment

Popular posts

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel