由于静态类型不能用作类型参数,因此无法通过viewmodel显示文件

时间:2022-04-27 16:12:12

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.

我已经在我的wabaplication中完成了一个文件上传,我正在制作查看这些图片并向用户显示的视图。我使用ViewModel向用户显示数据,当我尝试将List 添加到ViewModel时,我收到错误。

I have the folowing error :

我有以下错误:

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

'System.IO.File':静态类型不能用作类型参数

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

在公共List 文件的删除行上{get;在ViewModel类上设置;}。

Here is my ViewModel

这是我的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)

我该怎么做才能修复代码?我是否必须在ViewBag中传递文件(看起来很脏,因为ViewModel已经在这里)

Thanks to help me!

谢谢你的帮助!

1 个解决方案

#1


1  

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[].

你的问题正是错误所说的。您不能将静态类用作属性类型。如果你真的想将文件设置为ViewModel,你应该使用FileResult或FileContentResult或者只使用byte []。

#1


1  

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[].

你的问题正是错误所说的。您不能将静态类用作属性类型。如果你真的想将文件设置为ViewModel,你应该使用FileResult或FileContentResult或者只使用byte []。