2017-11-20 18 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); 
       } 
      } 
     } 
} 

업데이트입니다.

내가 만든 제품 편집 탭 에 추가 정보를 저장하는 제품 저장 이벤트가 있습니다. 거기서 나는 이렇게 요청서를 사용할 수 있습니다.

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 내 업데이트 답변보기, 나는 그것을 먼저 시도 :) –