【发布时间】:2021-07-30 14:07:47
【问题描述】:
我有一个 Web 应用程序,其中我的控制器将模型传递给父视图,如下所示:
public ActionResult Results()
{
//Processing
return View ("ParentView",model);
}
在我的“ParentView”中,我会像这样渲染一个局部视图:
@Html.Partial("_PartialView", anotherModel)
现在我根本不想碰anotherModel。
但我想做的是从ParentView 向_PartialView 传递一个值。
我知道我可以将类似 ViewBag.Value="Text" 的东西从 Controller 传递给 "ParentView",但是类似的东西从 "ParentView" 到 "_PartialView" 是否可行?
基本上,我想在"ParentView" 使用的model 中添加一个值,然后以某种方式将其传递给"_PartialView"
【问题讨论】:
-
带有标签 [model][controller] 和 [core](与 [.net] 无关),你的意思是像 asp.net-core-mvc 这样的吗?
标签: c# asp.net asp.net-mvc asp.net-core .net-core