MVC View: arguments like Html helper DisplayFor cannot be taken out of use

I am trying to use the HTML Displayper Extended Helper in this view:

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

with the following 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; } } } 

It gives me this error

Type arguments for the method 'System.Web.Mvc.Html.DisplayExtensions.DisplayFor (System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>)' cannot be taken out of use. Try explicitly specifying type arguments

I canโ€™t understand what happened. Please note that I can access the model in a strongly typed way when IntelliSense appears in the view. However, IntelliSense does not appear when I type a lambda expression.

+6
source share
1 answer

Now I worked, the problem was that the project was still compiled with .NET v3.5 instead of v4.0, see:

fooobar.com/questions/25817 / ...

+4
source

Source: https://habr.com/ru/post/909743/


All Articles