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:
我开始学习ASP.NET MVC,因为我在VB.NET商店工作,我正在从C#转换一个例子。我正在尝试实现强类型视图,我正在查看的示例显示以下内容:
<tr>
<td>Name:</td>
<td><%=Html.TextBox(x => x.Name)%></td>
</tr>
I've come up with the following in VB.NET:
我在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?
这种转换是否正确?这看起来真的很麻烦(我知道,我知道,VB.NET比C#更麻烦,但我没有选择)。如果是正确的,这是最好的方法吗?
2 个解决方案
#1
1
Why the call to ToString
? The exact conversion is this one :
为什么调用ToString?确切的转换是这样的:
<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
你可能有一个HtmlHelper som的扩展方法,因为TextBox没有内置的重载,它将Func
#2
0
I'd think (x As Contact).Name
would be sufficient, although it has been a while since I tried this with VB.NET...
我认为(x As Contact).Name就足够了,虽然我用VB.NET尝试了一段时间已经有一段时间了...
#1
1
Why the call to ToString
? The exact conversion is this one :
为什么调用ToString?确切的转换是这样的:
<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
你可能有一个HtmlHelper som的扩展方法,因为TextBox没有内置的重载,它将Func
#2
0
I'd think (x As Contact).Name
would be sufficient, although it has been a while since I tried this with VB.NET...
我认为(x As Contact).Name就足够了,虽然我用VB.NET尝试了一段时间已经有一段时间了...