Switch between DisplayTemplate in MVC DisplayFor

0

Is it possible to switch DisplayTemplate like below when we consume in different cshtml pages? Data1 and Data2 are two cshtml DisplayTemplates but referring same Data1 model.

If we are using without template name, its working and taking the Data1 template.

cshtml1.

DisplayFor(m=>m.Data1List,"Data1")

cshtml2.

 DisplayFor(m=>m.Data1List,"Data2")

I have received error like below when I tried this. but its working when I have only the first one.

System.InvalidOperationException
  HResult=0x80131509
  Message=The model item passed into the dictionary is of type 'System.Collections.Generic.List`1
c#
asp.net-mvc
asked on Stack Overflow Sep 17, 2020 by Keppy • edited Sep 17, 2020 by marc_s

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0