ASP.NET MVC 强类型视图从 C# 转换为 VB.NET
我开始学习 ASP.NET MVC,因为我在 VB.NET 商店工作,所以我正在从 C# 转换一个示例。我正在尝试实现强类型视图,我正在查看的示例显示以下内容:
<tr>
<td>Name:</td>
<td><%=Html.TextBox(x => x.Name)%></td>
</tr>
我在 VB.NET 中提出了以下内容:
<tr>
<td>Name:</td>
<td><%=Html.TextBox((Function(x As Contact) x.Name).ToString)%></td>
</tr>
此转换正确吗?这看起来确实很麻烦(我知道,我知道,VB.NET 比 C# 更麻烦,但我别无选择)。如果是正确的,这是最好的方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么调用
ToString
?确切的转换是这样的:您可能在其他地方有一个
HtmlHelper
的扩展方法,因为 TextBox 没有内置重载来接受Func
> 作为参数...所以你还需要转换该方法Why the call to
ToString
? The exact conversion is this one :You probably have an extension method for
HtmlHelper
somwhere else, since there is no built-in overload for TextBox that takes aFunc<Contact, string>
as a parameter... So you need to convert that method as well我认为
(x As Contact).Name
就足够了,尽管我用 VB.NET 尝试这个已经有一段时间了...I'd think
(x As Contact).Name
would be sufficient, although it has been a while since I tried this with VB.NET...