i used c# 7.2 (c# latest minor version (latest))
I want to send two model with Tuple and named items in view. in controller i create tuple with name:
public ActionResult Create(Guid fitnessPlanId)
{
#region GetCurrentFitnessPlan
var currentFitnessPlan= _service.FitnessPlanRepository.Get(fitnessPlanId, null, null);
if (currentFitnessPlan == null) return HttpNotFound();
#endregion
_currentUser = _service.UserRepository.GetUserByUsername(User.Identity.Name);
(FitnessPlan fitnessPlan , FitnessPlanDay fitnessPlanDay) tupleModel =(currentFitnessPlan, null);
return View(tupleModel);
}
and in view i wrote this:
@model (FitnessPlan fitnessPlan, FitnessPlanDay fitnessPlanDay)
when use tuple in view like this:
<th>@Html.DisplayNameFor(model => model.fitnessPlan.User.Sex)</th>
DisplayNameFor take me an error:
The type arguments cannot be inferred from the usage. Try specifying the type arguments explicitly.
I did research on the Internet, but I did not find any results. How can use Tuple By naming items in view ?
---Fixed---
Regarding the answer Georg Patscheider and this article :Can a C# named Tuple be used as an MVC page model type?
The only way to fix this problem was to change var tupleModel = new Tuple<FitnessPlan, FitnessPlanDay>(currentFitnessPlan, null);
in action controller and
the model to @model Tuple<FitnessPlan, FitnessPlanDay>
on the view and use <th>@Html.DisplayNameFor(model => model.Item1.User.Sex)</th>