Reputation: 50728
I have this C# code in a Razor view:
@(Html.CheckBoxFor<RazorSamplesWeb.Models.SamplesModel>(i => i.IsActive))
I tried translating it to this:
@Code Html.CheckBoxFor(Of RazorSamplesWeb.Models.SamplesModel)(Function(i) i.IsActive)End Code
But it's complaining. Why, and what is the right statement?
Thanks.
Upvotes: 1
Views: 4083
Reputation: 5024
If you don't have the @ModelType defined, the right statement is
@Html.CheckBoxFor(Function(m As RazorSamplesWeb.Models.SamplesModel) m.IsActive))
You explicitly set the generic type to RazorSamplesWeb.Models.SamplesModel.
Upvotes: 0
Reputation: 1038830
@(Html.CheckBoxFor<RazorSamplesWeb.Models.SamplesModel>(i => i.IsActive))
is too long, ugly and equivalent to:
@Html.CheckBoxFor(i => i.IsActive)
which in VB.NET might look like this:
@Html.CheckBoxFor(Function(i) i.IsActive)
The @Code
you are referring to could be used for helpers which do not return any value (IHtmlString) but write directly to the output buffer. Example:
@Code Html.RenderAction("Foo") End Code
Upvotes: 4
Reputation: 887453
@Code
blocks are used for standalone statements; they're equivalent to @{ ... }
in C#.
You should use a raw @
block.
Your C# code uses parentheses to force the parser to read past the HTML-like <...>
portion.
VB.Net doesn't have ambiguous generics syntax, so you don't need it.
Upvotes: 0