2012-12-14 17 views
0

我使用從Dynamic CSS using Razor Engine的例子,我有以下幾點:需要加載特定的CSS等候傳遞的參數

這是我_Layout.cshtml:

<link href="@Url.Action("Index", "Css")" rel="stylesheet" type="text/css" /> 

這是我CssController :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using RazorEngine; 

namespace SuburbanCustPortal.Controllers 
{ 
    public class CssController : Controller 
    { 
     // 
     // GET: /Css/ 

     public string Index(string id) 
     { 
      Console.WriteLine("id: " + id); 
      Response.ContentType = "text/css"; 
      return Razor.Parse(System.IO.File.ReadAllText(Server.MapPath("/Content/Site.css"))); 
     } 

    } 
} 

在哪裏我的問題是,我需要加載在當他們第一次訪問該網站通過一個特定的CSS文件的GUID(ID)懸而未決。上面的索引中的id出現爲null,但它正在加載。

例如:

mysite.com/account/login/xxxx-xxxx-xxxx-xxxx/

我需要加載基於該GUID的CSS。

是否可以從_Layout.cshtml中獲取該值,或者是否有另一種處理方法?

回答

1

你可以把一個GUID會議:

帳戶控制:

public ActionResult LogIn(Guid identifier) 
{ 
    Session["Identifier"] = identifier; 
    return View(); 
} 

在佈局:

<link href="@Url.Action("Index", "Css", new { id = Session["Identifier"] })" rel="stylesheet" type="text/css" /> 

CSS控制器:

public string Index(Guid id) 
    { 
     Console.WriteLine("id: " + id); 
     Response.ContentType = "text/css"; 
     return Razor.Parse(System.IO.File.ReadAllText(Server.MapPath("/Content/Site.css"))); 
    } 

您可以更改會議隨時可變從任何控制器

+0

感謝您的幫助! :) – ErocM

+0

歡迎:) – karaxuna

相關問題