Model view controller MVC视图:无法从用法推断Html helper DisplayFor的类型参数
我试图在此视图中使用扩展的HTML帮助程序DisplayFor:Model view controller MVC视图:无法从用法推断Html helper DisplayFor的类型参数,model-view-controller,c#-4.0,lambda,viewmodel,html-helper,Model View Controller,C# 4.0,Lambda,Viewmodel,Html Helper,我试图在此视图中使用扩展的HTML帮助程序DisplayFor: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcCms.Web.ViewModels.SubscriptionsViewModel>" %> <% using (Html.BeginForm("TrainingSubscription", "
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcCms.Web.ViewModels.SubscriptionsViewModel>" %>
<% using (Html.BeginForm("TrainingSubscription", "Account", FormMethod.Post))
{ %>
<%: Html.DisplayFor(m => m.Subscriptions) %>
<input type="submit" value="Save" />
<% } %>
m、 订阅量)%>
使用以下ViewModel
namespace MvcCms.Web.ViewModels
{
public class SubscriptionsViewModel
{
public string TrainingId { get; set; }
public string Subject { get; set; }
public IEnumerable<SubscriptionViewModel> Subscriptions { get; set; }
public SubscriptionsViewModel(string TrainingId, string Subject, IEnumerable<SubscriptionViewModel> Subscriptions)
{
this.TrainingId = TrainingId;
this.Subject = Subject;
this.Subscriptions = Subscriptions;
}
}
public class SubscriptionViewModel
{
public string ContactId { get; set; }
public string FullName { get; set; }
public bool Subscribed { get; set; }
public SubscriptionViewModel(string ContactId, string FullName, bool Subscribed)
{
this.ContactId = ContactId;
this.FullName = FullName;
this.Subscribed = Subscribed;
}
}
}
namespace MvcCms.Web.ViewModels
{
公共类订阅视图模型
{
公共字符串TrainingId{get;set;}
公共字符串主题{get;set;}
公共IEnumerable订阅{get;set;}
公共订阅视图模型(字符串训练ID、字符串主题、IEnumerable订阅)
{
this.TrainingId=TrainingId;
this.Subject=主语;
this.Subscriptions=订阅;
}
}
公共类订阅视图模型
{
公共字符串ContactId{get;set;}
公共字符串全名{get;set;}
公共bool订阅{get;set;}
public SubscriptionViewModel(字符串ContactId、字符串FullName、bool Subscripted)
{
this.ContactId=ContactId;
this.FullName=FullName;
本.认购=认购;
}
}
}
它给了我这个错误
方法的类型参数
'System.Web.Mvc.Html.DisplayExtensions.DisplayFor(System.Web.Mvc.HtmlHelper,System.Linq.Expressions.Expression>)'
无法从用法推断。尝试显式指定类型参数
我不知道怎么了。请注意,我能够通过视图中弹出的IntelliSense以强类型方式访问模型。但是,当我键入lambda表达式时,IntelliSense不会弹出。我现在可以使用它了,问题是该项目仍然使用.NET v3.5而不是v4.0编译,请参见:
我最近发现,视图的确构建得很好,并且工作正常,唯一的问题是设置视图时没有IntelliSense弹出窗口和令人讨厌的红线/错误。我也面临着同样的问题。你能用外行的术语指导我如何解决这个问题吗。要循序渐进。我会非常感激的。