tags:

views:

21

answers:

1

Below is the short version of my code, it's very basic. In my page model, I have an enumerable field that I'm passing into an Action() method. The problem is, right before Html.Action() is invoked in the view, it's NOT null. However, once it's inside the child action, it's suddenly null - as if it's not being passed in.

On a similar attempt, I tried doing Html.Partial("OverlayAlerts", Model.Alerts) and it still passes the data in as null. I'm not sure why this is. When debugging, the Alerts property is being populated before calling the Action() (or Partial()) method. Any ideas? Thanks.

PAGE CONTROLLER ACTION

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

    return View(model); 
}

MODEL:

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

VIEW

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

CHILD ACTION (same controller)

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

Try this:

<%: Html.Action("GetOverlayAlerts", new {alerts = Model.Alerts})%>
Nick Aceves
THAT WORKED! Now, what would I do for passing directly into a view using Html.Partial() ?
Ryan Peters
@Ryan: You can post that as a new question if you like.
Timwi