我通过一个构造函数传入一个字符串,我想在我的模型类中使用它作为我的错误信息:
public class ContactForm
{
public string NameError { get; set; }
public ContactForm(string nameError)
{
NameError = nameError;
}
[Required(ErrorMessage = NameError)]
public string Name { get; set; }
//More properties
}
我在这里得到例外:
An object reference is required for the non-static field, method, or property 'UmbracoSport.Models.ContactForm.NameError.get' D:\Umbraco\Websites\UmbracoSport\UmbracoSport\Models\Custom\ContactForm.cs 19 34 UmbracoSport
如果我使NameError静态,我会收到此错误:
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type D:\Umbraco\Websites\UmbracoSport\UmbracoSport\Models\Custom\ContactForm.cs 19 34 UmbracoSport
这有可能吗?