The framework I am using is .Net 8
I want to follow these two tutorials to achieve ErrorMessage
with different language.
Why can’t I use resources as ErrorMessage with DataAnnotations?
Blazor WebAssembly Client DataAnnotations Localization
Here is the path of the resources file:
And I have set Access Modifier to public already:
What’s more, I have set the resources file path in program.cs also:
<code>builder.Services.AddLocalization(options=>options.ResourcesPath="Resources");
</code>
<code>builder.Services.AddLocalization(options=>options.ResourcesPath="Resources");
</code>
builder.Services.AddLocalization(options=>options.ResourcesPath="Resources");
However, when I code it like this:
<code> private sealed class InputModel
{
[Required(ErrorMessageResourceName = "ErrorMessageUserNameRequire", ErrorMessageResourceType = typeof(SharedResource))]
[EmailAddress]
public string Email { get; set; } = "";
[Required(ErrorMessageResourceName = "ErrorMessagePasswordRequire", ErrorMessageResourceType = typeof(SharedResource))]
[DataType(DataType.Password)]
public string Password { get; set; } = "";
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
</code>
<code> private sealed class InputModel
{
[Required(ErrorMessageResourceName = "ErrorMessageUserNameRequire", ErrorMessageResourceType = typeof(SharedResource))]
[EmailAddress]
public string Email { get; set; } = "";
[Required(ErrorMessageResourceName = "ErrorMessagePasswordRequire", ErrorMessageResourceType = typeof(SharedResource))]
[DataType(DataType.Password)]
public string Password { get; set; } = "";
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
</code>
private sealed class InputModel
{
[Required(ErrorMessageResourceName = "ErrorMessageUserNameRequire", ErrorMessageResourceType = typeof(SharedResource))]
[EmailAddress]
public string Email { get; set; } = "";
[Required(ErrorMessageResourceName = "ErrorMessagePasswordRequire", ErrorMessageResourceType = typeof(SharedResource))]
[DataType(DataType.Password)]
public string Password { get; set; } = "";
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
Visual Studio reports error:
<code>Severity Code Description Project File Line Suppression State Details
Error CS0246 The type or namespace name 'SharedResource' could not be found (are you missing a using directive or an assembly reference?)
</code>
<code>Severity Code Description Project File Line Suppression State Details
Error CS0246 The type or namespace name 'SharedResource' could not be found (are you missing a using directive or an assembly reference?)
</code>
Severity Code Description Project File Line Suppression State Details
Error CS0246 The type or namespace name 'SharedResource' could not be found (are you missing a using directive or an assembly reference?)
What’s wrong with my code?