views:

247

answers:

2

I'm starting to learn ASP.NET MVC and since I work in a VB.NET shop I'm converting an example from C#. I'm trying to implement a strongly typed view and the example I'm looking at shows the following:

<tr>
  <td>Name:</td>
  <td><%=Html.TextBox(x => x.Name)%></td>
</tr>

I've come up with the following in VB.NET:

<tr>
  <td>Name:</td>
  <td><%=Html.TextBox((Function(x As Contact) x.Name).ToString)%></td>
</tr>

Is this conversion correct? This seems really cumbersome (I know, I know, VB.NET is more cumbersome than C#, but I have no choice in the matter). If it is correct, is it the best way?

A: 

I'd think (x As Contact).Name would be sufficient, although it has been a while since I tried this with VB.NET...

synhershko
+1  A: 

Why the call to ToString ? The exact conversion is this one :

<tr>
  <td>Name:</td>
  <td><%=Html.TextBox(Function(x) x.Name)%></td>
</tr>

You probably have an extension method for HtmlHelper somwhere else, since there is no built-in overload for TextBox that takes a Func<Contact, string> as a parameter... So you need to convert that method as well

Thomas Levesque
I converted to string because when I didn't VS2008 complained that "Lambda expression cannot be converted to string because string is not a delegate type". As you said, I must be missing something so I'll have to revisit.
ren33