Я использую частичное представление на двух отдельных страницах, а частичное представление использует метаданные для получения отображаемых имен в форме атрибутов в модели (стандартный способ выполнения метаданных).
Мне нужносделать контекст отображаемого имени чувствительным в зависимости от страницы.
С этой целью я расширяю атрибут System.ComponentModel.DisplayNameAttribute и передаю массив области / controller / action / resourcefile / resourcestring, чтобы я мог выбратьправильная строка ресурса в зависимости от контекста.
Моя проблема заключается в том, как получить область / контроллер / действие из следующего:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonInterfaces.Helpers;
namespace CommonInterfaces.ComponentModel
{
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public class ContextSensitiveDisplayName : System.ComponentModel.DisplayNameAttribute
{
public class Context
{
public string Area { get; set; }
public string Controller { get; set; }
public string Action { get; set; }
public Type ResourceType { get; set; }
public string ResourceKey { get; set; }
public Context(string area, string controller, string action, Type resourceType, string resourceKey)
{
this.Area = area;
this.Controller = controller;
this.Action = action;
this.ResourceType = resourceType;
this.ResourceKey = resourceKey;
}
}
public ContextSensitiveDisplayName(params Context[] contexts)
{
/* Its these values that I need */
string currentArea = "";
string currentController = "";
string currentAction = "";
Context selectedContext =
contexts.FirstOrDefault(m =>
(m.Area == currentArea) &&
(m.Controller == currentController) &&
(m.Action == currentAction)
);
this.DisplayNameValue = ""; // Use the selectContext to retrieve string from resource file.
}
}
}
Любая помощь с этим будет принята с благодарностью,