2017-11-20 12 views
0

これで、アクションフィルタが機能しましたが、一括編集フォームから値を引き出す方法がわかりません。nopcommerceアクション内のバルクプロダクト編集フォームから値を取得する

私は依存関係レジストラにフィルタを登録しました。

using Nop.Admin.Controllers; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web.Mvc; 

namespace Nop.Plugin.Feed.Froogle.Actions 
{ 
    public class BulkEditOverideActionFilter : ActionFilterAttribute, IFilterProvider 
    { 
     public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) 
     { 
      if (controllerContext.Controller is ProductController && actionDescriptor.ActionName.Equals("BulkEditUpdate", StringComparison.InvariantCultureIgnoreCase)) 
      { 
       return new List<Filter>() { new Filter(this, FilterScope.Action, 0) }; 
      } 
      return new List<Filter>(); 
     } 

     public override void OnActionExecuting(ActionExecutingContext filterContext) 
     { 
      System.Diagnostics.Debug.WriteLine("The filter action is = " + filterContext.ActionDescriptor.ActionName.ToString()); 
      if (filterContext != null)// && amazonListingActive == true 
      { 
       var form = (FormCollection)filterContext.ActionParameters.FirstOrDefault(x => x.Key == "form").Value; 
       foreach (var i in form.Keys) 
       { 
        System.Diagnostics.Debug.WriteLine("The key value is = " + i); 
       } 
      } 
     } 
    } 

誰もが、私はこれをaccompluishかもしれない方法を知っている:

はここに私のフィルタです。

+0

あなたは特に何をしたいですか? –

+0

@ディヴァー私が言ったことのために私の答えを見て、歓声 –

答えて

0

私はそれを理解しました。 フォームはnamevaluecollectionを返します。したがって、これを使用して値を取得する必要がありました。

public override void OnActionExecuting(ActionExecutingContext filterContext) 
{ 
     var httpContext = HttpContext.Current; 
     if (httpContext != null && httpContext.Request.Form.HasKeys()) 
     { 

      var form = filterContext.HttpContext.Request.Form; 
      var products = form.AllKeys.SelectMany(form.GetValues, (k, v) => new { key = k, value = v }); 
      System.Diagnostics.Debug.WriteLine("The form is = " + form); 

      if (form != null) 
      { 
       foreach (var pModel in products) 
       { 
        System.Diagnostics.Debug.WriteLine("The pModel.Key is = " + pModel.key); 
        System.Diagnostics.Debug.WriteLine("The pModel.Value is = " + pModel.value); 
       } 
      } 
     } 
} 

UPDATEこれは、私はそれをこのようにしなかった理由は、リクエストフォームを使用できませんでした。

私は製品を保存するイベントを持っています。これは、追加の 製品編集タブで情報を保存するために使用します。そこに私はそのようなリクエストフォームを使用することができます。

public class ProductSaveConsumer : IConsumer<EntityFinalised<Product>> 
{ 
    public void HandleEvent(EntityFinalised<Product> eventMessage) 
    { 
     var httpContext = HttpContext.Current; 
     if (httpContext != null) { 
      amazonProduct = new AmazonProduct(); 
      var form = httpContext.Request.Form; 
      //now I can grab my custom form values 
      if (!String.IsNullOrEmpty(form["AmazonProductSKU"])) 
       amazonProduct.AmazonProductSKU = form["AmazonProductSKU"].ToString(); 
     } 
    } 
} 

しかし、一括編集フィルタは、NameValueCollectionのを返す、だから私は 使用Request.Form

希望、これは他の誰かを助けませんでした:)

+0

ちょうどRequest.Formをkeyvaluepair列挙可能にキャストできませんでしたか? – Raphael

+0

@Raphael私の更新された答えを見て、私はそれを試した:) –

関連する問題