开发者

ASP.NET MVC strongly typed view convert from C# to VB.NET

开发者 https://www.devze.com 2022-12-13 05:07 出处:网络
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 follow

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 reall开发者_如何学Pythony 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?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消