问题描述
我试图创建一个强类型的局部视图
I'm trying to create a strongly typed partial view
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Pt.Data.Services>>" %>
<table>
<% foreach (Pt.Data.Services item in Model)
{ Html.RenderPartial("ServiceItem",item); } %>
</table>
在控制器:
IEnumerable<Services> Model=null;
using (tl ctx = new tl(Config.ConnectionString))
{
Model = ctx.Services.ToList();
}
return View("List",Model);
在与二进制组件项目运行时,这workied以及 System.Web.Mvc
引用。
This workied well when running in a project with the binary assembly System.Web.Mvc
referenced.
但是,如果我删除二进制组件并用MVC源调试添加项目,终止确认强类型的意见。
But if I remove binary assembly and add a project with MVC sources for debugging, it stops recognizing strongly typed views.
它的工作就像一个的ViewPage
而不是的ViewPage&LT;&的TModel GT;
It's working like a ViewPage
instead of ViewPage<TModel>
至于结果,我发现了错误:
As result I'm getting the error:
编译器错误信息:CS1579:foreach语句无法在类型对象的变量操作,因为'对象'不包含'GetEnumerator'`一个公共定义
为什么会编译MVC,但不与源这项工作?我怎样才能使源正常运行?
Why would this work with the compiled MVC, but not with the sources? And how can I make the sources run correctly?
推荐答案
有你在〜/浏览次数改变了这一行/ Web.config文件:
Have you changed this line in ~/Views/Web.config:
<pages validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter,
System.Web.Mvc, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl,
System.Web.Mvc, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35">
本:
<pages validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter,
System.Web.Mvc, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=NULL"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=NULL"
userControlBaseType="System.Web.Mvc.ViewUserControl,
System.Web.Mvc, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=NULL">
其实这史蒂夫·桑德森的的可能会有所帮助。
这篇关于强类型的视图差异(MVC的来源与组装)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!