I have a partial which initially renders when the page first loads. And then When I click on nav-tab
, it creates another set of partial
inside my View. It should update the same partial without creating a new set of it.
Controller
public ActionResult Index()
{
ClsHome model = new ClsHome();
return View(model);
}
public PartialViewResult EmployeeBasedCountry(int CountryId)
{
ClsHome clshome = new ClsHome();
clshome.Country = CountryId;
clshome.countries = CountryFilter(CountryId);
return PartialView("~/Views/Home/_pEmp.cshtml", clshome);
}
View
@model EmpWebsite.Models.Home.ClsHome
<div id=Partial class="col-md-5">
@Html.Partial("_pEmp")
</div>
Partial
@model EmpWebsite.Models.Home.ClsHome
<ul class="nav nav-tabs nav-justified">
<li class="active">@Html.ActionLink("Australia", "EmployeeBasedCountry", "Home", new @CountryId = "1" },new{@class = "ActionLinkId"})
</li>
<li>@Html.ActionLink("New Zealand", "EmployeeBasedCountry", "Home", new {@CountryId = "2" },new{@class = "ActionLinkId"})</li>
</ul>
<div class="tab-content">
<div class="panel">
<table class="table-striped">
<tr class="heading">
<th>
EmpId
</th>
<th>
EmpName
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@item.EmpId
</td>
<td>
<a>@item.EmpName</a>
</td>
</tr>
}
</table>
</div>
</div>
Script
$(document).on("click", '.ActionLinkId', function (e) {
e.preventDefault();
$.ajax({
url: $(this).attr("href"),
type: "GET",
}).done(function (partialViewResult) {
debugger;
$("#Partial").html(partialViewResult);
});
});
See Question&Answers more detail:os