4

私は次のPagedListModelを持っています:

public class PagedClientViewModel
{
    public int? Page { get; set; }
    public PagedList.IPagedList<ClientViewModel> Clients { get; set; }               
}

public class ClientViewModel
{        
    public string ClientNumber { get; set; }
    public bool UseThisClient{ get; set; }
}

私の見解は次のようになります。

@using (Html.BeginForm("Index", "Home", FormMethod.Get, new { id = "Form" }))
{
    @foreach (var item in Model.Clients)
    {
       @Html.DisplayFor(modelItem => item.ClientNumber)
       @Html.CheckBoxFor(modelItem => item.UseThisClient)
    }    

 @Html.HiddenFor(model => model.Clients)            
}

コントローラのアクション:

 public ActionResult Index(PagedClientViewModel model)
 {
  //...process all clients in the list
 }

チェックされているチェックボックスを処理できるようにモデルをコントローラーにポストバックしたいのですが、次のエラーが発生します。エラーはインターフェイスをポストバックしているためであると理解していますが、方法が見つかりません。その周り。どうすればこの作品を手に入れることができますか?

インターフェイスのインスタンスを作成できません。System.RuntimeType.CreateInstanceSlow(Boolean publicOnly、Boolean skipCheckThis、Boolean fillCache、StackCrawlMark&stackMark)at System.RuntimeTypeでSystem.RuntimeTypeHandle.CreateInstance(RuntimeType type、Boolean publicOnly、Boolean noCheck、Boolean&canBeCached、RuntimeMethodHandleInternal&ctor、Boolean&bNeedSecurityCheck) (ブールpublicOnly、ブールskipCheckThis、ブールfillCache、StackCrawlMark&stackMark)
at System.Activator.CreateInstance(Type type、Boolean nonPublic)
System.Activator.CreateInstance(Type type)at System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext、ModelBindingContext bindingContext、Type modelType)at System.Web.Mvc.DefaultModelBinder.BindSimpleModel(ControllerContext controllerContext、ModelBindingContext bindingContext、ValueProviderResult valueProviderResult) System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext、ModelBindingContext bindingContext)at System.Web.Mvc.DefaultModelBinder.GetPropertyValue(ControllerContext controllerContext、ModelBindingContext bindingContext、PropertyDescriptor propertyDescriptor、IModelBinder propertyBinder)
System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext、ModelBindingContext bindingContext、PropertyDescriptor propertyDescriptor)at System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext、ModelBindingContext bindingContext)at System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext 、ModelBindingContext bindingContext、オブジェクトモデル)
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext、ModelBindingContext bindingContext)at System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext、ModelBindingContext bindingContext)at System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext、ParameterDescriptor parameterDescriptor )at System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext、ActionDescriptor actionDescriptor)atSystem.Web.Mvc.Async.AsyncControllerActionInvoker。<>c_ DisplayClass25.b _1e(AsyncCallback asyncCallback、Object asyncState)atSystem.Web.Mvc。 Async.AsyncResultWrapper.WrappedAsyncResult1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) at System.Web.Mvc.Controller.<>c__DisplayClass1d.<BeginExecuteCore>b__17(AsyncCallback asyncCallback, Object asyncState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallbackコールバック、オブジェクト状態)でSystem.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultでBegin(AsyncCallbackコールバック、オブジェクト状態、Int32タイムアウト)1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__2(AsyncCallback asyncCallback, Object asyncState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext、AsyncCallback callback、Object state)at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext、AsyncCallback callback、オブジェクトの状態)at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context、AsyncCallback cb、Object extraData)at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()at System.Web.HttpApplication.ExecuteStep(IExecutionStep step、Boolean&completedSynchronously)

4

1 に答える 1

9

この問題の回避策は、ページングメタデータを個別のプロパティとして渡し、ビューでIPagedListを再構築することです。以下のように

public class PagedClientViewModel
{
    public int? Page { get; set; }
    public List<ClientViewModel> Clients { get; set; }
    public IPagedList PagingMetaData { get; set; } 
}

メタデータの生成

pagedClientViewModel.PagingMetaData = new StaticPagedList<ClientViewModel>(pagedClientViewModel.Clients, pageIndex, pageSize, TotalClients).GetMetaData();

ビューでポケットベルを作成する

<div style="text-align: center">
    @Html.PagedListPager(new StaticPagedList<ClientViewModel>(Model.Clients, Model.PagingMetaData), page => Url.Action("<actionname>", new { page }), PagedListRenderOptions.Classic)
</div>
于 2013-01-19T14:51:27.150 に答える