Show Files trough viewmodel isn't possible because of static types cannot be used as type arguments

69 views Asked by At

I've done a file upload in my wabaplication and I'm making the view that retrieve thos epictures and show them to the user. I use ViewModel show data to user and I get error when i try to add List<File> to the ViewModel.

I have the folowing error :

'System.IO.File': static types cannot be used as type arguments

on the line of the delcaration of public List<File> files {get; set;} on the ViewModel class.

Here is my ViewModel

    public class AuditAndCritereViewModel {
    public string name {get; set;}
// 10+ another fields
    public List<File> files {get; set;}
    }
public AuditAndCritereViewModel(int auditId)
        {// init fields}

Here is my controller:

Public Actionresult Get(int id)
{
AuditAndCritereViewModel model = new AuditAndCritereViewModel(id);
return View(model);
}

How Can I do to fix the code? Do I have to pass files in ViewBag (looks dirty for me because ViewModel is already here)

Thanks to help me!

1

There are 1 answers

1
teo van kot On BEST ANSWER

Your problem is exactly what error say. You can't use static class as property type. If you really want to set file to ViewModel you should use FileResult or FileContentResult or just byte[].