Click here to Skip to main content
15,905,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here's the c# code that I am having trouble converting to VB:

C#
<div class="form-group">
@Html.LabelFor(m => m.FromName, new { @class = "col-md-2 control-label" })
  <div class="col-md-10">
    @Html.TextBoxFor(m => m.FromName, new { @class = "form-control" })
    @Html.ValidationMessageFor(m => m.FromName)
  </div>
</div>

The c# line I'm having trouble with is those ones with @Html syntax.

The VB code (below) that I have for those has this error on m.FromName:
"Late binding operations cannot be converted to an expression tree"

Here's what I have in VB:
VB
@Html.LabelFor(Function(m) m.FromName, New With {Key .class = "col-md-2 control-label"})
Posted

You don't have to ask such questions every time you need a translation. Most if not all of this work can be done automatically. Please see my past answer: Code Interpretation, C# to VB.NET[^].

With ASP.NET it may require some more effort, but you still can easily figure out the translation itself.

—SA
 
Share this answer
 
Comments
bobishkindaguy 10-Nov-15 8:33am    
Thanks, I should have mentioned that none of the converters seem to work on this correctly. I've spent several hours already on this before asking the question here. It's not for lack of effort; rather I am new to Razor.

I think it's the part: new { @class = "col-md-2 control-label" } that is not converting. The converter gives me:
New With { .[class] "col-md-2 control-label" }

(Note the square brackets around "class", which is an improvement over what I mentioned above as a possible translation.)

But even though this might look right, I then get the error I mentioned (which I think is not the real problem):
"Late binding operations cannot be converted to an expression tree".
The red wiggly line is under m.FromName.
HTML
@Html.LabelFor(m => m.FromName, new { @class = "col-md-2 control-label" })
<label for="FromName">From Name</label>

@Html.TextBoxFor(m => m.FromName, new { @class = "form-control" })
<input type="text" class="from-control" name="FromName" id="FromName">
</input>


Equivalent HTML code is written below the razor code - Now convert it to your VB syntax.


-KR
 
Share this answer
 
Comments
bobishkindaguy 10-Nov-15 8:37am    
Thanks KR, I see what you mean. In fact, your solution would work in VB or C#.

What I need is to understand the syntax C# uses, new { @class = "xxx" } and how VB does this. It's not just Razor but Lambda that I struggle with here. Your thoughts?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900