2017-12-27 80 views
0

콜백 중에 컨트롤러에 devexpress gridview 모델 바인딩을 전달하고 싶지만 실패합니다.콜백 동안 devexpress gridview에 컨트롤러로 모델 바인딩을 보내는 방법?

모델

public class UploadExcelError 
{ 
    public int rowNumber { get; set; } 
    public string errorMessage { get; set; } 
} 

public class UploadViewModel 
{ 
    public List<UploadExcelError> UploadExcelErrors { get; set; } 
    public UploadFile UploadFile { get; set; } 
} 

UploadErrorPartial.cshtml

@using ControlTower2.Models 
@model ControlTower2.Models.UploadViewModel 

@if (Model != null) 
{ 
    if (Model.UploadExcelErrors != null) 
    { 

     @Html.DevExpress().GridView(
      settings => 
      { 
       settings.Name = "gridViewExcelError"; 
       settings.CallbackRouteValues = new { Controller = "PurchaseOrder", Action = "FilteringError", xyz = Model }; 
       settings.SettingsBehavior.AllowSort = false; 
       settings.SettingsPager.Mode = GridViewPagerMode.ShowAllRecords; 
       settings.Columns.Add(column => { column.FieldName = "rowNumber"; column.Caption = "Excel Row#"; }); 
       settings.Columns.Add(column => { column.FieldName = "errorMessage"; column.Caption = "Error Message"; }); 
       settings.Settings.ShowHeaderFilterButton = true; 
       var headerFilterMode = GridHeaderFilterMode.List; 
       foreach (GridViewDataColumn column in settings.Columns) 
        column.SettingsHeaderFilter.Mode = headerFilterMode; 
      } 
     ).Bind(Model.UploadExcelErrors).GetHtml() 
    } 
} 

컨트롤러

public ActionResult FilteringError(UploadViewModel xyz) 
{ 
    return PartialView("UploadErrorPartial", xyz); 
} 

은 위의 코드에서 null입니다.

는 또한 시도 :

settings.CallbackRouteValues = new { Controller = "PurchaseOrder", Action = "FilteringError", xyz = Model.UploadExcelErrors }; 

public ActionResult FilteringError(List<UploadExcelError> xyz) 
{ 
    UploadViewModel uploadViewModel = new UploadViewModel(); 
    uploadViewModel.UploadExcelErrors = xyz; 
    return PartialView("UploadErrorPartial", uploadViewModel); 
} 

xyz가 null이 아니라 수는 0입니다. 이 작동하지 않습니다 이유입니다, 컨트롤러을 ViewData에만 데이터를 전송 볼 -

UPDATE에게을 :하지만 내가 너무을 ViewData을 시도

UploadErrorPartial.cshtml

데이터의 4 개 행을 보여있다.

if (Model.UploadExcelErrors != null) 
{ 
    ViewData["xyz"] = Model; 
    @Html.DevExpress().GridView(
     settings => 
     { 
      settings.Name = "gridViewExcelError"; 
      settings.CallbackRouteValues = new { Controller = "PurchaseOrder", Action = "FilteringError" }; 
      settings.SettingsBehavior.AllowSort = false; 
      settings.SettingsPager.Mode = GridViewPagerMode.ShowAllRecords; 
      settings.Columns.Add(column => { column.FieldName = "rowNumber"; column.Caption = "Excel Row#"; }); 
      settings.Columns.Add(column => { column.FieldName = "errorMessage"; column.Caption = "Error Message"; }); 
      settings.Settings.ShowHeaderFilterButton = true; 
      var headerFilterMode = GridHeaderFilterMode.List; 
      foreach (GridViewDataColumn column in settings.Columns) 
       column.SettingsHeaderFilter.Mode = headerFilterMode; 
     } 
    ).Bind(Model.UploadExcelErrors).GetHtml() 
} 

public ActionResult FilteringError() 
{ 
    UploadViewModel uploadViewModel = (UploadViewModel)ViewData["xyz"]; 
    return PartialView("UploadErrorPartial", uploadViewModel); 
} 

uploadViewModel(UploadViewModel)ViewData["xyz"]에서 null을 얻는다.

답변

0

나는 세션을 사용하여 Model.UploadExcelErrors을 저장하고 내 문제를 해결합니다.