在C#7中,您可以命名元组:

var foo = (Name: "Joe", Age: 42);

如果我使用以下方法将其传递给MVC模型:
return View(foo);

那么,在cshtml文件中应使用什么语法来声明模型?尽管这不起作用,但类似...
@model (string Name, int Age);

最佳答案

至于当前时间,您不能使用

@model Tuple<string, int>
//or
@model ValueTuple<string, int>

对于两个选项之间的区别:What's the difference between System.ValueTuple and System.Tuple?

您可以在GitHub上关注:Razor throws CompilationFailedException when iterating over named Tuple(我知道它作为dup已关闭,但名称更能说明当前情况)

09-27 03:38
查看更多