Generic List property in ViewModel
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
add a comment |
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
1
The type argument would need to be at the class level
– Nkosi
Nov 13 '18 at 13:40
add a comment |
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
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
c# generics model-view-controller asp.net-mvc-viewmodel
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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>
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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>
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
add a comment |
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>
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
add a comment |
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>
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>
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
The type argument would need to be at the class level
– Nkosi
Nov 13 '18 at 13:40