我是一个ASP MVC 3 noobie通过音乐商店教程工作,但将所有内容翻译成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
但编译器抛出错误(如上所示)。似乎认为错误信息是专辑的属性。
我该怎么做才能解决这个问题?
答案 0 :(得分:9)
这应该是:
<Required(ErrorMessage := "Price is required")> _
<StringLength(160)> _
答案 1 :(得分: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