ASP.NET MVC Razor rendering

2019-08-05 16:57发布

问题:

Why does the following code renders my child action:

<div class='h-l'>
  @if (ViewBag.Hide)
  {
     @Html.Action(MVC.City.GetCitiesList().AddRouteValue("makeBig", false));
  }
</div>

but if I delete @ before @Html.Action, nothing is rendered?

回答1:

From MSDN

ChildActionExtensions.Action Method.
Invokes a child action method and returns the result as an HTML string.

You should use @ to determine a string as a method. Take a look at ASP.Net @ Symbol