【发布时间】:2020-09-01 04:30:22
【问题描述】:
我正在 Asp .Net Core 3.1 中进行共享资源本地化。为此,我创建了资源目录并创建了 SharedResources.cs 文件。
Root/Resources/SharedResources.cs
Root/Resources/SharedResources.en.resx
我在控制器中注入了代码。
public AccountController(IStringLocalizer<SharedResources> sharedLocalizer)
{
_sharedLocalizer = sharedLocalizer;
}
public IActionResult Login(LoginViewModel model)
{
if(loginSuccess == true)
{
return RedirectToAction("Dashboard", "Dashboard");
}
TempData["Error"] = _sharedLocalizer["Error"];
return View(model);
在 SharedResources.en.resx
Key : Error
Value : Invalid User
在 SharedResources.cs
namespace RootName
public class SharedResources
{
}
它显示错误并且应该显示Invalid User。我哪里错了?
【问题讨论】:
-
嗨@Abhi,我的回答对你有帮助吗?如果有,你能accept as answer吗?如果没有,你能跟进让我知道吗?
标签: asp.net-core model-view-controller localization globalization shared-resource