1

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 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

The reason is because you can use html tags in a code block. And you can insert strings inside them. Thus any command without @ will be determined as a simple string.
Shymep, but why then it doesn't render this "string" in case I don't type @?
Unfortunately I haven't succeeded in finding an article on MDSN describing rendering inside code blocks. Seems exactly @ answers for rendering. Otherwise it's just a command (if not inside a tag block).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.