I am using asp .net core 3, I add some multiple partial via javascript
function AddBill(type)
{ tag = "....."; // some div and a tags
$.get('/Glasses/DisplayFarBill?index=' + farIndex,
function (partial) {
$('#FarSightedBillsSection').append(tag);
$('#farSighted' + farIndex).append(partial);
$('#farSighted' + farIndex).collapse('show');
farIndex++;
});
}
I have multiple ViewData
property on parent that has filled in controller via db context, if I add partialview
with tag, partials recognize parent ViewData
, but when I add them via javascript, they don't and I should again fill them in action and access to db multi times.
public ActionResult DisplayFarBill(int index)
{
ViewData["Index"] = index;
//ViewData["LenseCover"] = new SelectList(_context.LenseCover, "Id", "Name");
//ViewData["FrameBrand"] = new SelectList(_context.FrameBrand, "Id", "Name");
//ViewData["FrameModel"] = new SelectList(_context.FrameModel, "Id", "Name");
//ViewData["LenseBrand"] = new SelectList(_context.LenseBrand, "Id", "Name");
BillFarSighted billFarSighted = new BillFarSighted
{
PackFactor = 1,
LenseCoverId = 2
};
return PartialView("BillFarSighted", billFarSighted);
}
how can I send Parent ViewData to partial?