【发布时间】:2020-09-11 05:00:32
【问题描述】:
我正在使用 asp .net core 3,我通过 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++;
});
}
我在父节点上有多个 ViewData 属性,它通过数据库上下文填充控制器,如果我添加带有标签的 partialview,部分识别父 ViewData,但是当我通过 javascript 添加它们时,它们不会并且我应该再次填写它们并多次访问数据库。
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);
}
如何将父 ViewData 发送到部分?
【问题讨论】:
标签: asp.net-core asp.net-mvc-partialview