我想將每個操作方法參數名稱及其 相應的值記錄在數據庫中作爲鍵值對。作爲 的一部分,我使用OnActionExecuting ActionFilterAttribute,因爲它將會是正確的地方(OnActionExecuting方法將調用 所有控制器動作方法調用)來獲取Action Executing上下文。Asp .Net MVC正在執行操作 - 獲取用戶定義類型的操作參數值在執行操作時的值
我得到.Net類型(string,int,bool)的值。但我 無法獲取用戶定義類型(自定義類型)的值。 (例如:登錄模式)。我的模型也可能有一些其他嵌套用戶定義的類型。
我試圖獲取用戶定義類型的值,但我 獲取唯一的類名字符串。我希望我們可以在 中做反思。
請問任何人協助解決問題。因爲我是新的 來反思。這對我有幫助。提前致謝。 我需要在OnActionExecuting中獲取這些類型的名稱和值。
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
ActionParameter = new SerializableDictionary<string,string>();
if(filterContext.ActionParameter != null)
{
foreach(var paramter in filterContext.ActionParameter)
{
//able to get returnUrl value
//unable to get model values
ActionParameter.Add(paramter.Key, paramter.Value);
}
}
}
public ActionResult Login(LoginModel model, string returnUrl)
{
return View(model);
}
用戶定義類型
public class LoginModel
{
public string UserName {get;set;}
public string Password {get;set;}
//User defined type
public UserRequestBase Request {get;set;}
}
//User defined type
public class UserRequestBase
{
public string ApplicationName {get;set;}
}
我能夠得到OnActionExecuting的RETURNURL(登錄方法PARAM)的值,而不是模型(登錄方法PARAM)。我能夠看到值,但不知道如何訪問它,儘管我無法獲取它,但我需要泛型,因爲我在控制器中有20個方法,所以我不僅可以使用LoginModel。
你可能想看看這個:http://stackoverflow.com/questions/9758051/get-type-using-reflection – wahwahwah 2014-11-20 20:02:38
正如在鏈接中提到的,我們需要提供「Item」作爲鍵getProperty,但是在這裏我不知道屬性名稱,因爲它對於每個操作方法可能會有所不同。 。actualData.getType()的getProperty( 「項目」)PropertyType.Name。 – Prem 2014-11-20 20:08:24
請任何人都可以幫忙嗎? – Prem 2014-11-21 07:43:03