2012-01-18 1 views
1

Jeremy Skinner는 MVC Contrib에서 스프레드 시트를 내보내는 것에 대한 블로그와 비디오를 제공합니다. 문제는 동영상이나 블로그에서 필터링이 수행되지 않는다는 것입니다. 그리드가 포함 된 페이지와 관련된 컨트롤러에서 필자는 필터가 있고 "스프레드 시트로 내보내기"와 연결된 컨트롤러에서 재설정하지 않고 필터가 필요합니다. 문제는 "내보내기 대상"을 클릭 할 때마다 변수가 재설정된다는 것입니다. .?. 스프레드 시트 "링크를 나는MVC Contrib를 사용하여 한 컨트롤러에서 다른 컨트롤러로 변수를 전달하는 방법은 무엇입니까?

다음

제레미의 링크 http://www.jeremyskinner.co.uk/2010/04/28/mvccontrib-grid-presentation입니다 재설정하지 않고 한 컨트롤러에서 다른 컨트롤러로 그 변수를 어떻게합니까 주셔서 감사합니다!

답변

0

나는이 같은 세션 변수 생성 결국 :

1 다음과 같이 web.config를 편집하여 세션 변수를 활성화합니다.

2- 0 초 콘트롤

string firstName = (string)(Session["FirstName"]); 
0

사용 TempData [ ","] 객체 제 제어기

Session["FirstName"] = FirstNameTextBox.Text; 

-3- 사용 세션 상태에서 세션 상태를 만든다.

귀하의 뷰 모델은 다소처럼 보일 것입니다 :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ComponentModel; 
using MvcContrib.Pagination; 
using MvcContrib.UI.Grid; 
using System.Web.Mvc; 

namespace MyMVCProject.ViewModels 
{ 
    public class SubscriptionViewModel 
    { 
     public int SubscriptionID { get; set; }   
     public string SubNo { get; set; }    
    } 
    public class SubscriptionListContainerViewModel 
    { 
     public IPagination<SubscriptionViewModel> SubscriptionPagedList { get; set; } 
     public SubscriptionFilterViewModel Filters { get; set; } 
     public GridSortOptions GridSortOptions { get; set; } 
     public int? TotalCount { get; set; } 
    } 
    public class SubscriptionFilterViewModel 
    { 
     public int? CustomerID { get; set; } 
     public int? PlanID { get; set; }   
    } 
} 

컨트롤러의 액션은 다음과 같다 :

public ActionResult Index(SubscriptionListContainerViewModel model, GridSortOptions gridSortOptions, int? page) 
      { 
       SubscriptionFilterViewModel filter = new SubscriptionFilterViewModel(); 
       if (model.Filters != null) 
       { 
        filter.CustomerID = model.Filters.CustomerID; 
        filter.PlanID = model.Filters.PlanID; 
       } 
       TempData["Filters"]=filter; 
      //code for IPagination<SubscriptionViewModel> population. 
      } 

내보내기 기능 :

public void Export() 
     { 
      SubscriptionFilterViewModel filter = (SubscriptionFilterViewModel)TempData["Filters"]; 
      TempData["Filters"]=filter; 
      //code for IPagination<SubscriptionViewModel> population and excel creation. 
      //output the excel after creation 

      Guid fileId = Guid.NewGuid(); 
      string strFileName = Convert.ToString(fileId) + ".xls"; 
      string strFilePathnName = HttpContext.Server.MapPath ("~/Content/Uploads/Excels/Export/") + strFileName; 
      MemoryStream file = new MemoryStream(); 
      hssfworkbook.Write(file); 
      System.IO.File.WriteAllBytes(strFilePathnName, file.GetBuffer()); 
      System.IO.FileInfo inf = new FileInfo(strFilePathnName); 
      HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=Blogs" + inf.Extension); 
      HttpContext.Response.ContentType = "application/ms-excel"; 
      HttpContext.Response.TransmitFile(HttpContext.Server.MapPath ("~/Content/Uploads/Excels/Export/" + strFileName)); 
     } 

전화하여 "Excel로 내보내기"의 수출 활동 버튼을 클릭하십시오.

+0

의견을 보내 주셔서 감사합니다.하지만 내 모습은 상당히 다릅니다. 나는 제레미와 아주 흡사합니다. 공개 ActionResult 내보내기() { \t \t \t var customers = customerRepository.FindAll(); \t \t \t 창 ExcelResult 새로운 (고객) \t \t \t \t .Columns (열 => { \t \t \t \t \t column.For (X => x.Id) \t \t \t \t \t 칼럼. (x => x.Name)의 경우 : \t \t \t \t \t column.For (x => x.DateOfBirth) .Format ("{0 : d}"); \t \t \t \t}); \t \t} –

관련 문제