Generic List property in ViewModel












0















I'm looking to include a generic List property in my ViewModel to enable me to fill that with any kind of IEnumerable list.



It's essentially to create a very simple reporting structure which then uses custom display templates to render a tabular form of the object



Is that possible?



public class ReportingViewModel
{
public List<T> Data { get; set; }
public string Title { get; set; }
}


Then using a model in my custom display template



@model List<object>


Or similar. I've tried it using List<T> or List<object> in both the VM and custom template but to no avail.










share|improve this question




















  • 1





    The type argument would need to be at the class level

    – Nkosi
    Nov 13 '18 at 13:40
















0















I'm looking to include a generic List property in my ViewModel to enable me to fill that with any kind of IEnumerable list.



It's essentially to create a very simple reporting structure which then uses custom display templates to render a tabular form of the object



Is that possible?



public class ReportingViewModel
{
public List<T> Data { get; set; }
public string Title { get; set; }
}


Then using a model in my custom display template



@model List<object>


Or similar. I've tried it using List<T> or List<object> in both the VM and custom template but to no avail.










share|improve this question




















  • 1





    The type argument would need to be at the class level

    – Nkosi
    Nov 13 '18 at 13:40














0












0








0


1






I'm looking to include a generic List property in my ViewModel to enable me to fill that with any kind of IEnumerable list.



It's essentially to create a very simple reporting structure which then uses custom display templates to render a tabular form of the object



Is that possible?



public class ReportingViewModel
{
public List<T> Data { get; set; }
public string Title { get; set; }
}


Then using a model in my custom display template



@model List<object>


Or similar. I've tried it using List<T> or List<object> in both the VM and custom template but to no avail.










share|improve this question
















I'm looking to include a generic List property in my ViewModel to enable me to fill that with any kind of IEnumerable list.



It's essentially to create a very simple reporting structure which then uses custom display templates to render a tabular form of the object



Is that possible?



public class ReportingViewModel
{
public List<T> Data { get; set; }
public string Title { get; set; }
}


Then using a model in my custom display template



@model List<object>


Or similar. I've tried it using List<T> or List<object> in both the VM and custom template but to no avail.







c# generics model-view-controller asp.net-mvc-viewmodel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 13:40









Nkosi

111k16123190




111k16123190










asked Nov 13 '18 at 13:37









Simon BennettsSimon Bennetts

216




216








  • 1





    The type argument would need to be at the class level

    – Nkosi
    Nov 13 '18 at 13:40














  • 1





    The type argument would need to be at the class level

    – Nkosi
    Nov 13 '18 at 13:40








1




1





The type argument would need to be at the class level

– Nkosi
Nov 13 '18 at 13:40





The type argument would need to be at the class level

– Nkosi
Nov 13 '18 at 13:40












1 Answer
1






active

oldest

votes


















1














The type argument would need to be at the class level



public class ReportingViewModel<T> {
public List<T> Data { get; set; }
public string Title { get; set; }
}


and accessed in the view



@model ReportingViewModel<MyObject>





share|improve this answer
























  • Thanks for the reply. Does this mean I would still require a custom template for each object type? I'm trying to avoid that and having a single Table.cshtml template which takes any object?

    – Simon Bennetts
    Nov 13 '18 at 13:59













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282250%2fgeneric-listt-property-in-viewmodel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The type argument would need to be at the class level



public class ReportingViewModel<T> {
public List<T> Data { get; set; }
public string Title { get; set; }
}


and accessed in the view



@model ReportingViewModel<MyObject>





share|improve this answer
























  • Thanks for the reply. Does this mean I would still require a custom template for each object type? I'm trying to avoid that and having a single Table.cshtml template which takes any object?

    – Simon Bennetts
    Nov 13 '18 at 13:59


















1














The type argument would need to be at the class level



public class ReportingViewModel<T> {
public List<T> Data { get; set; }
public string Title { get; set; }
}


and accessed in the view



@model ReportingViewModel<MyObject>





share|improve this answer
























  • Thanks for the reply. Does this mean I would still require a custom template for each object type? I'm trying to avoid that and having a single Table.cshtml template which takes any object?

    – Simon Bennetts
    Nov 13 '18 at 13:59
















1












1








1







The type argument would need to be at the class level



public class ReportingViewModel<T> {
public List<T> Data { get; set; }
public string Title { get; set; }
}


and accessed in the view



@model ReportingViewModel<MyObject>





share|improve this answer













The type argument would need to be at the class level



public class ReportingViewModel<T> {
public List<T> Data { get; set; }
public string Title { get; set; }
}


and accessed in the view



@model ReportingViewModel<MyObject>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 13:42









NkosiNkosi

111k16123190




111k16123190













  • Thanks for the reply. Does this mean I would still require a custom template for each object type? I'm trying to avoid that and having a single Table.cshtml template which takes any object?

    – Simon Bennetts
    Nov 13 '18 at 13:59





















  • Thanks for the reply. Does this mean I would still require a custom template for each object type? I'm trying to avoid that and having a single Table.cshtml template which takes any object?

    – Simon Bennetts
    Nov 13 '18 at 13:59



















Thanks for the reply. Does this mean I would still require a custom template for each object type? I'm trying to avoid that and having a single Table.cshtml template which takes any object?

– Simon Bennetts
Nov 13 '18 at 13:59







Thanks for the reply. Does this mean I would still require a custom template for each object type? I'm trying to avoid that and having a single Table.cshtml template which takes any object?

– Simon Bennetts
Nov 13 '18 at 13:59




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282250%2fgeneric-listt-property-in-viewmodel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly