2012-04-25 5 views
7

Hi ở đó tôi đã hành động sau đây trong điều khiển của tôiKý tự không hợp lệ trong đường dẫn. Lỗi khi sử dụng Skip và Take với IEnumerable

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Index() 
{ 
    IEnumerable<SurveyResult> myresult = filterData(); 
    totalCount = myresult.Count<SurveyResult>(); 
    ViewBag.totalCount = totalCount; 
    //myresult = myresult.Skip<SurveyResult>(100 * pageIndex).Take<SurveyResult>(100); 
    return View(myresult); 
} 

Đây là quan điểm của tôi

@model IEnumerable<SurveyResult> 
@{ 
    ViewBag.Title = "Survey Results"; 
} 
@using (Html.BeginForm()) 
{ 

    <table class="std-tbl"> 
     <thead> 
      <tr> 
       <th> 
        DEL 
       </th> 
       ... 

       <th> 
       </th> 
      </tr> 
     </thead> 
     @Html.DisplayFor(x => x, new { pageIndex = ViewBag.index }) 
    </table> 
} 

tôi có một cái nhìn một phần cho SurveyResult nhưng tôi không bao gồm bởi vì tôi không nghĩ nó có liên quan. Đây là câu hỏi của tôi. Đoạn mã trên là làm việc tốt nhưng ngay sau khi tôi bỏ ghi chú dòng sau

myresult = myresult.Skip<SurveyResult>(100 * pageIndex).Take<SurveyResult>(100); 

tôi nhận được "nhân vật bất hợp pháp trên đường đi." Tôi nghĩ rằng nó có thể tìm ra PartialView cho SurveyResult. Tôi không hiểu tại sao nó có thể tìm thấy nó khi dòng trên được bình luận nhưng nó không thể khi nó không được chú ý? Cảm ơn bạn.

Đây là của tôi stack trace

[ArgumentException: Illegal characters in path.] 
    System.IO.Path.CheckInvalidPathChars(String path) +126 
    System.IO.Path.Combine(String path1, String path2) +38 
    System.Web.Compilation.DiskBuildResultCache.GetPreservedDataFileName(String cacheKey) +27 
    System.Web.Compilation.DiskBuildResultCache.GetBuildResult(String cacheKey, VirtualPath virtualPath, Int64 hashCode, Boolean ensureIsUpToDate) +14 
    System.Web.Compilation.BuildManager.GetBuildResultFromCacheInternal(String cacheKey, Boolean keyFromVPP, VirtualPath virtualPath, Int64 hashCode, Boolean ensureIsUpToDate) +200 
    System.Web.Compilation.BuildManager.GetVPathBuildResultFromCacheInternal(VirtualPath virtualPath, Boolean ensureIsUpToDate) +51 
    System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +68 
    System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +111 
    System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound) +125 
    System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.FileExists(String virtualPath) +29 
    System.Web.Mvc.BuildManagerViewEngine.FileExists(ControllerContext controllerContext, String virtualPath) +41 
    System.Web.Mvc.VirtualPathProviderViewEngine.GetPathFromGeneralName(ControllerContext controllerContext, List`1 locations, String name, String controllerName, String areaName, String cacheKey, String[]& searchedLocations) +150 
    System.Web.Mvc.VirtualPathProviderViewEngine.GetPath(ControllerContext controllerContext, String[] locations, String[] areaLocations, String locationsPropertyName, String name, String controllerName, String cacheKeyPrefix, Boolean useCache, String[]& searchedLocations) +304 
    System.Web.Mvc.VirtualPathProviderViewEngine.FindPartialView(ControllerContext controllerContext, String partialViewName, Boolean useCache) +130 
    System.Web.Mvc.<>c__DisplayClass8.<FindPartialView>b__7(IViewEngine e) +21 
    System.Web.Mvc.ViewEngineCollection.Find(Func`2 lookup, Boolean trackSearchedPaths) +127 
    System.Web.Mvc.ViewEngineCollection.FindPartialView(ControllerContext controllerContext, String partialViewName) +170 
    System.Web.Mvc.Html.TemplateHelpers.ExecuteTemplate(HtmlHelper html, ViewDataDictionary viewData, String templateName, DataBoundControlMode mode, GetViewNamesDelegate getViewNames, GetDefaultActionsDelegate getDefaultActions) +418 
    System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData, ExecuteTemplateDelegate executeTemplate) +1117 
    System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData) +66 
    System.Web.Mvc.Html.TemplateHelpers.TemplateFor(HtmlHelper`1 html, Expression`1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData, TemplateHelperDelegate templateHelper) +117 
    System.Web.Mvc.Html.TemplateHelpers.TemplateFor(HtmlHelper`1 html, Expression`1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData) +100 
    System.Web.Mvc.Html.DisplayExtensions.DisplayFor(HtmlHelper`1 html, Expression`1 expression, Object additionalViewData) +57 
    ASP._Page_Views_SurveyResult_Index_cshtml.Execute() in c:\Source\Test\Admin\Views\SurveyResult\Index.cshtml:163 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207 
    System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +81 
    System.Web.WebPages.StartPage.RunPage() +19 
    System.Web.WebPages.StartPage.ExecutePageHierarchy() +65 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76 
    System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +220 
    System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115 
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +303 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13 
    System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +23 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +260 
    System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +19 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +177 
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343 
    System.Web.Mvc.Controller.ExecuteCore() +116 
    System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97 
    System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10 
    System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37 
    System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21 
    System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62 
    System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50 
    System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7 
    System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60 
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8969117 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184 

Here is the source Error: 

Dòng 161: Dòng 162: Dòng 163: @ Html.DisplayFor (x => x, mới {pageIndex = ViewBag.index}) Dòng 164: Dòng 165:}

+0

Dấu vết ngăn xếp là gì? – SLaks

+0

chỉ là FYI (không liên quan đến câu hỏi của bạn) bạn không cần phải cung cấp các tham số kiểu chung trong hầu hết các trường hợp, nó có thể được suy ra từ loại 'IEnumerable' –

+0

@MichaelEdenfield Tôi chỉ thay đổi để bỏ qua hoặc lấy và có lỗi tương tự cho cả hai – atbebtg

Trả lời

18

DisplayFor đang tìm kiếm chế độ xem được đặt tên theo tên của các lớp triển khai được tạo bởi EF, chứa ký tự không hợp lệ.

Thử gọi .ToList() trong bộ điều khiển.

+0

Điều đó đã làm được. Tại sao nó hoạt động nếu tôi không gọi lấy và/hoặc bỏ qua? – atbebtg

+0

Vì sau đó loại là 'DbSet ', được đặt tên tốt. – SLaks

+0

Điều này có liên quan gì đến việc tải không? – Phil