m.Subscriptions) %> 使用以下 ViewModel namespace-6ren">
gpt4 book ai didi

model-view-controller - MVC View : Type arguments Html helper DisplayFor cannot be inferred from the usage

转载 作者:行者123 更新时间:2023-12-04 08:24:58 27 4
gpt4 key购买 nike

我正在尝试在此 View 中使用扩展的 HTML Helper DisplayFor:

<%@ 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" />
<% } %>

使用以下 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;
}
}
}

它给了我这个错误

The type arguments for method 'System.Web.Mvc.Html.DisplayExtensions.DisplayFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>)' cannot be inferred from the usage. Try specifying the type arguments explicitly



我无法弄清楚出了什么问题。请注意,我可以在 View 中弹出 IntelliSense 的情况下以强类型方式访问模型。但是,当我输入 lambda 表达式时,IntelliSense 没有弹出。

最佳答案

我现在开始工作了,问题是该项目仍然使用 .NET v3.5 而不是 v4.0 编译,请参阅:

https://stackoverflow.com/a/7142200/1232507

关于model-view-controller - MVC View : Type arguments Html helper DisplayFor cannot be inferred from the usage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9517669/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com