我創建瞭如下一個Custom Action Filter
有3個屬性:如何將ParentController屬性傳遞給自定義操作篩選器?
public class TrackUser : ActionFilterAttribute, IActionFilter
{
public string BaseUrl { get; set; }
public string Service { get; set; }
public HealthUtil.PageCode Pagecode { get; set; }
public void OnActionExecuting(ActionExecutingContext filterContext)
{
// Some logic to execute
}
}
我試圖用我的行動,低於這個客戶行爲過濾器:
[TrackUser(BaseUrl =baseUrl, Service =service1, Pagecode =HealthUtil.PageCode.HealthHome)]
public ActionResult AddLead(leadViewModel leaddata)
{
}
酒店baseUrl
在ParentController定義類如下:
public static string baseUrl
{
get { return "http://localhost:52985/api/"; }
//set { baseUrl = value; }
}
問題是我無法將baseUrl
傳遞給動作過濾器。我米得到以下錯誤信息:
的屬性參數必須是常量表達式的typeof屬性參數類型
請引導和幫助我解決這個問題的表達式或數組創建表達式。
編輯 baseUrl
在ParentController必須有一個屬性,因爲後面的代碼將App.Config中讀取它。
它必須屬性,因爲我會讀取這個值的形式App.Config 請任何建議。 – user576510 2014-11-05 00:41:32
@ user576510它不能動態,錯誤信息甚至會告訴你。 – DavidG 2014-11-05 01:02:08