I’m sure it’s something small (or maybe big), but my child action isn’t working. I have a childaction that populates a List with year values. This list is to be displayed via a partial control. I see the respective pieces of code executed when I step through the code, yet nothing renders on the page.
Child Action:
[ChildActionOnly]
public ActionResult GetYearList()
{
return PartialView(_FormService.getYears());
}
Call used in parent view:
<% using (Html.BeginForm()) {%>
<%= Html.ValidationSummary(true) %>
Select Year: <% Html.Action("GetYearList"); %>
Partial View code:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<SelectListItem>>" %>
<% if (Model != null)
{ %>
<% Html.DropDownList("Year", Model, "Select Year"); %>
<% } else { %>
<p> No Years Found </p>
<% } %>
Any clue what I’m doing wrong? I could just render the partial view directly, but I’m really trying to figure out how the ChildActions work so I use them in the future should that logic be more complicated.
edit 1
Silly semantics. Had to change my GetYearList partial view to:
<%= Html.DropDownList("Year", Model, "Select 1099 Year") %>
instead of
<% Html.DropDownList("Year", Model, "Select Year"); %>
Same sort of thing on parent view as Darin stated:
change Select Year: <% Html.Action("GetYearList"); %>
to <%= Html.Action("Get1099YearList") %>
You are invoking the child action but doing nothing to render it to the output:
should become:
or if you prefer:
And their Razor equivalents for those who might be interested: