gpt4 book ai didi

c# - Html.Action ("MyView", Model.SomeData) 作为 null 传入?

转载 作者:行者123 更新时间:2023-11-30 20:11:27 25 4
gpt4 key购买 nike

下面是我的代码的简短版本,非常基础。在我的页面模型中,我有一个要传递给 Action() 方法的可枚举字段。问题是,就在 View 中调用 Html.Action() 之前,它不是空的。但是,一旦它进入子操作,它就会突然变为 null - 就好像它没有被传入一样。

在类似的尝试中,我尝试执行 Html.Partial("OverlayAlerts", Model.Alerts) 并且它仍然将数据作为 null 传递。我不确定这是为什么。调试时,在调用 Action()(或 Partial())方法之前填充 Alerts 属性。有任何想法吗?谢谢。

页面 Controller 操作

public ActionResult Index() 
{
var model = new DashboardModel()
{
...
Alerts = GadgetService.GetAlerts()
...
};

return View(model);
}

型号:

public class DashboardModel
{
...
public IEnumerable<AlertMessage> Alerts { get; set; }
...
}

查看

<%: Html.Action("GetOverlayAlerts", Model.Alerts)%>

CHILD ACTION(同一 Controller )

[ChildActionOnly]
public ActionResult GetOverlayAlerts(IEnumerable<AlertMessage> alerts)
{
alerts.Any(); // <--- FAILS: alerts is passed through as null?
}

最佳答案

试试这个:

<%: Html.Action("GetOverlayAlerts", new {alerts = Model.Alerts})%>

关于c# - Html.Action ("MyView", Model.SomeData) 作为 null 传入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3773006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com