Here I tried using TempData to pass data from controller action method to partial view. But it does not work.
My Controller Code
public class PropertyController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult GetRequestReport()
{
List<ReportsInfo> reportsList = reportsManager.GetRequestReport(UserName, Locality, "usp_GetResults");
int count = reportsList.Select(x => x.UserId).Distinct().Count();
TempData["Count"] = count;
return PartialView("_Partial1", reportsList);
}
public ActionResult Test(string id)
{
switch (id)
{
case "tab1":
return PartialView("_Results");
case "tab2":
return PartialView("_Results2");
}
return new EmptyResult();
}
}
Index.cshtml
<div id="div-for-partial">
</div>
$(function () {
$('.tab').click(function () {
var id = this.id;
$.get('@Url.Action("Test")', { "id": id }, function (data) {
$('#div-for-partial').html(data);
$('.mvc-grid').mvcgrid();
});
});
});
_Results Partial View
@TempData["Count"]
<br />
<div id="reportList">
@Html.AjaxGrid(Url.Action("GetRequestReport", "Property"))
</div>
_Partial1 Partial View
@model Project.Models.ReportsInfo
@(
Html.Grid(Model)
.Build(columns =>
{
columns.Add(model => model.ApproverName).Titled("Approver Name");
})
.Empty("No records found.")
.Sortable()
.Pageable(pager =>
{
pager.RowsPerPage = 15;
})
)
I have even tried view bag but no luck is there any way to achieve it. Basically I want to pass count of results in TempData and use in partial view