Is it possible to use a C # named Tuple as the model type of an MVC page?

In C # 7, you can have tuple names:

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

If you pass this to the MVC model using:

 return View(foo); 

Then what syntax should be used in the cshtml file to declare the model? Although this does not work, something like ...

 @model (string Name, int Age); 
+8
c # tuples model named
source share
1 answer

As for the current time, you cannot and should not use

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

For the difference between two parameters: What is the difference between System.ValueTuple and System.Tuple?

You can follow GitHub: Razor throws a CompilationFailedException when iterating over a named Tuple (I know that it is closed as a duplicate, but the name is more indicative of the current case)

+5
source share

All Articles