このは、あなたが今探している答えではありませんが、異なる構成と同じサイトを使用して再考しなければ、私は動的にCSSのなどを変更するために、最近何をしたかを見てみましょう:
私は、ウェブサイトの各「バージョン」がクエリ文字列内で一意の参照を使用することに決めました。これに基づいて、正しいコンテンツを見つけ出し、モデルにパスをロードしてビューに送信します。ここ
コントローラの:
public ActionResult Index()
{
List<string> listOfAcceptableRef = new List<string>() { "uniqueCode1", "uniqueCode2" };
string uniqueRef=null;
if (Request.QueryString["ref"]!=null)
policyRef = Request.QueryString["ref"].ToLower();
if (string.IsNullOrWhiteSpace(uniqueRef) || (!string.IsNullOrWhiteSpace(uniqueRef) && !listOfAcceptableRef.Contains(uniqueRef)))
{
throw new Exception("This reference key is unknown.");
//return RedirectToAction("KeyError");
}
return View(GetPageContext(uniqueRef));
}
は、クエリ文字列から基準コードを取得し、コンテキスト・ファクトリから関連CSSパスを含むモデルを生成します。
ここに私のモデルです:
public class PageContext
{
public string Ref { get; set; }
public string TabId { get; set; }
public string TabName { get; set; }
public string SiteTitle { get; set; }
public string CssPath { get; set; }
public PageContext()
{
Products = new List<ProductInfo>();
}
}
そして、私のコンテキストファクトリ:CSSのパスなどで
public class ContextFactory<T>
{
private ContextFactory()
{
}
static readonly Dictionary<string, Type> _dict = new Dictionary<string, Type>()
{
{ "uniqueRef1", Type.GetType("The.Full.Page.Namespace.UniqueSite1Context")},
{ "uniqueRef2", Type.GetType("The.Full.Page.Namespace.UniqueSite2Context")}
};
public static bool Create(string reference, out T context)
{
context = default(T);
Type type = null;
if (_dict.TryGetValue(reference, out type))
{
context = (T)Activator.CreateInstance(type);
return true;
}
return false;
}
}
そして、実際のコンテキストインスタンス:すべてのその後
public class UniqueSite1Context : PageContext
{
public UniqueSite1Context()
{
this.Ref = "uniqueSite1";
this.CssPath = "Content/UniqueSite1Context.css";
this.DisclaimerPath = "Content/UniqueSite1Context.pdf";
this.SiteTitle = "UniqueSite1";
}
}
、ちょうどモデルのパスを使用してCSSをレンダリングします。
構造的に言えば、これを拡張して(の概念)、ユーザーが移動する「サイト」に基づいて異なるロジックおよびデータコンテキストを使用することができます。
しかし、結果として得られるHTMLのアプリケーションには、異なるクラスやIDなどはありませんか? –
はいメンテナンスを最小限に抑えるため、2つのアプリケーションのHtmlは可能な限り同じです。 – Lobsterpants
私はダウン票を得たwhayを知って愛する? – Lobsterpants