How to Use Partial View in MVC3 and MVC4 with Examples

So many times , developer face the issues , how to replace asp.net User Control , with MVC , So simples solution use Partial View.

Step 1: Make Action inside of Controller

Example

[ChildActionOnly]

public ActionResult CourseCategory()

{

var genres = db.CourseCategorys.ToList();

return PartialView(genres);

}

Step 2: Partial View Source code
 

@model IEnumerable<MVC4EF5_DEMO.Models.CourseCategory>

 

<ul id="categories">

@foreach (var CategoryID in Model)

{

<li>@Html.ActionLink(CategoryID.Name,

"Browse", "Predict",

new { CategoryID = CategoryID.CourseCategoryID }, null)

</li>

}

</ul>

Step 3: How to call according to your need.

@{Html.RenderAction("CourseCategory", "CourseCategory");}

Anywhere you call according to ur requirement.

Plz If this code is useful for anybody plz send your valuable comment.