2

我是一个 ASP MVC 3 新手,通过音乐商店教程工作,但将所有内容都翻译成 VB(我在 VB 商店工作)。

该教程有一行:

public class Album
{
    [Required(ErrorMessage = "An Album Title is required")]
    [StringLength(160)]
    public string   Title      { get; set; }
}

我如何将它翻译成VB?显而易见的选择是:

Public Class Album

    <Required(ErrorMessage = "Price is required")> //Compiler says:'ErrorMessage' is not declared. It may be inaccessible due to its protection level.
    <StringLength(160)>
    Property Title As String
    Property Price As Decimal

End Class

但是编译器抛出错误(如上所示)。似乎认为错误消息是专辑的属性。

我能做些什么来解决这个问题?

4

2 回答 2

9

这应该是:

<Required(ErrorMessage := "Price is required")> _
<StringLength(160)> _

查看有关属性的 VB 文档以获取更多信息。

于 2012-08-10T16:39:49.983 回答
0
Public Class Album
    <Required(ErrorMessage := "An Album Title is required")> _
    <StringLength(160)> _
    Public Property Title() As String
        Get
            Return m_Title
        End Get
        Set
            m_Title = Value
        End Set
    End Property
    Private m_Title As String
End Class
于 2012-08-10T16:40:23.773 回答