2009-12-25 11 views
13

यदि आपके पास एक्शन विधि में मॉडल-बाध्य पैरामीटर है, तो आप एक्शन फ़िल्टर में उस पैरामीटर पर कैसे जा सकते हैं?एएसपी.नेट एमवीसी एक्शनफिल्टर पैरामीटर बाइंडिंग

[MyActionFilter] 
public ActionResult Edit(Car myCar) 
{ 
    ... 
} 

public class MyActionFilterAttribute : ActionFilterAttribute 
{ 
    public void OnActionExecuted(ActionExecutedContext filterContext) 
    { 
     //I want to access myCar here 
    } 

} 

फार्म चर के माध्यम से जा के बिना mycar प्राप्त करने के लिए वैसे भी वहाँ है?

+0

यहाँ एक महान कैसे प्रमाणीकरण उद्देश्यों के लिए उपयोग करने के लिए ActionParameters समझा लेख है: http://www.joe-stevens.com/2010/ 08/1 9/एएसपी-नेट-एमवीसी-प्रमाणीकरण-विशेषता-उपयोग-क्रिया-पैरामीटर-साथ-द-एक्शनफिल्टरट्रिब्यूट/ –

उत्तर

11

के बारे में OnActionExecuted लेकिन आप OnActionExecuting में कर सकते हैं सुनिश्चित नहीं हैं:

public class MyActionFilterAttribute : ActionFilterAttribute 
{ 
    public override void OnActionExecuting(ActionExecutingContext filterContext) 
    { 
     // I want to access myCar here 

     if(filterContext.ActionParameters.ContainsKey("myCar")) 
     { 
      var myCar = filterContext.ActionParameters["myCar"] as Car; 

      if(myCar != null) 
      { 
       // You can access myCar here 
      } 
     } 
    } 
} 
+1

मुझे नहीं लगता कि आप एक्शनफिल्टर का उपयोग कर सकते हैं, यह एक्शनफिल्टर एट्रिब्यूट है। ActionExecutedContext पर आपको एक्शन पैरामीटर संपत्ति कहां मिली? –

+0

धन्यवाद, यह ActionFilterAttribute है - आप सही हैं। मैंने देखा नहीं है कि सवाल ऑनएक्शन एक्स्क्टेड के बारे में है। –

+0

धन्यवाद दोस्तों। ActionFilterAttribute को राज्य करने के लिए मेरा मूल प्रश्न संपादित करें। – Shlomo

संबंधित मुद्दे