У меня есть метод расширения для получения строки из файла ресурсов в asp.net mvc 3
public static string Resource(this HtmlHelper htmlHelper, string expression, params object[] args)
{
string path = ((RazorView)htmlHelper.ViewContext.View).ViewPath;
var fields =
(ResourceExpressionFields)
(new ResourceExpressionBuilder()).ParseExpression(expression, typeof(string), new ExpressionBuilderContext(path));
return (!string.IsNullOrWhiteSpace(fields.ClassKey))
? string.Format((string)htmlHelper.ViewContext.HttpContext.GetGlobalResourceObject(
fields.ClassKey,
fields.ResourceKey,
CultureInfo.CurrentUICulture), args)
: string.Format((string)htmlHelper.ViewContext.HttpContext.GetLocalResourceObject(
path,
fields.ResourceKey,
CultureInfo.CurrentUICulture), args);
}
Вот как я использую этот метод
@Html.LabelFor(m => m.Login, Html.Resource("LoginBoxLoginField"))
Но я не знаю, как использовать его в действии контроллера
public ActionResult MyAction()
{
//how to get string from resource file using my extension method?
}
Например
if (!ModelState.IsValid)
ModelState.AddModelError(string.Empty, string.Empty/* should be resource string */);