Asp.net mvc 4 如何使元组在mvc 5中工作,VS2017

Asp.net mvc 4 如何使元组在mvc 5中工作,VS2017,asp.net-mvc-4,asp.net-mvc-5,visual-studio-2017,Asp.net Mvc 4,Asp.net Mvc 5,Visual Studio 2017,我的项目已经在C#7.0上: 我已经安装了编译器和System.ValueTuple: 我的视图模型是: @model IEnumerable<GHCOMvc.Models.PriorAddressModel> <table class="table"> <tr> <th> @Html.DisplayNameFor(model => model.Address.Address) </th>

我的项目已经在C#7.0上:

我已经安装了编译器和System.ValueTuple:

我的视图模型是:

@model  IEnumerable<GHCOMvc.Models.PriorAddressModel>

<table class="table">
  <tr>
    <th>
      @Html.DisplayNameFor(model => model.Address.Address)
    </th>
  </tr>
</table>
@model IEnumerable
@DisplayNameFor(model=>model.Address.Address)
一切都很顺利

当我把它改成这个:

@using GHCOMvc.Controllers

@model  (IEnumerable<GHCOMvc.Models.PriorAddressModel> List, BaseController.Modes mode)

<table class="table">
  <tr>
    <th>
      @Html.DisplayNameFor(model => model.Address.Address)
    </th>
  </tr>
</table>
使用GHCOMvc.控制器 @模型(IEnumerable列表、BaseController.Modes) @DisplayNameFor(model=>model.Address.Address) 它给出了错误:

错误CS8059功能“元组”在C#6中不可用。请使用 语言版本7或更高版本


这不是一个核心项目,所以我还没有Startup.cs文件。我可以添加一个来解决这个问题,但我不清楚如何做,因为这不是一个核心项目。

我不知道您的具体问题,但我以前在编译razor文件时遇到过类似的问题。检查您的目标框架。记住,razor是在部署之后编译的。我敢打赌,如果你升级你的目标框架,你会看到你的问题得到解决。

更新到
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
1.0.4
1.0.3
为我解决了这个问题:

注意我必须手动编辑csproj文件,以删除对
1.0.3
的引用,然后才能将其生成

那么,在我看来,我可以做到:

@model  (IEnumerable<GHCOMvc.Models.PriorAddressModel> list, BaseController.Modes mode)

<table class="table">
  <tr>
    <th>
      @Html.DisplayNameFor(model => model.list.FirstOrDefault().Address.Address)
    </th>
  </tr>
</table>
@model(IEnumerable列表,BaseController.Modes)
@DisplayNameFor(model=>model.list.FirstOrDefault().Address.Address)

设置为4.6.2。你想做什么改变?一个包含c#7的版本。您需要一个支持您正在使用的功能的工具集,因为razor将在运行时编译。目标4.7当我去Nuget检查4.7时(我甚至不知道它存在,所以非常感谢),我看到了一个我以前没有注意到的更新通知。该书于2017年4月27日出版。无论如何,该更新修复了它,没有升级到4.7。但我可能会升级到4.7,因为7>6。这是一个比我更好的答案。@ChiralMichael,没有你我是不会找到的:)