我正在尝试为我的所有文件输入创建一个用于MVC4的EditorTemplate,我正在使用blueimp jquery-file-upload插件,并且它工作得很好,但我对编辑器模板有些怀疑:
我有一个类绑定到编辑器模板,如下所示:
public class FileUpload
{
public int Id { get; set; }
public string FileName { get; set; }
public string TempFileName { get; set; }
public bool Deleted { get; set; }
public bool Modified { get; set; }
...
public class MultiFileUpload : List<FileUpload>
{
}
在我想要上传文件的ViewModel中我有这个:
public class TestModel
{
[Required]
[MaxLength(3)]
public MultiFileUpload File { get; set; }
}
这是我的EditorTemplate(/Views/Shared/EditorTemplates/MultiFileUpload.cshtml):
@model MultiFileUpload
<div class="file-upload">
<ul class="list-group files-list">
@for (var i = 0; i < Model.Count; i++)
{
<li class='list-group-item'>
@Html.HiddenFor(m => m[i].Id)
@Html.HiddenFor(m => m[i].Deleted)
@Html.HiddenFor(m => m[i].TempFileName)
@Html.HiddenFor(m => m[i].FileName)
@Model[i].FileName
<a href="#" class="delete pull-right" style="margin-right:-15px; text-decoration:none;"><i class="icon-remove"></i></a>
</li>
}
</ul>
<span class="btn btn-default fileinput-button">
<i class="icon-plus"></i>
<span>Add File</span>
<input type="file" name="" data-url="api/fileupload" data-single="false" />
</span>
</div>
我希望在TestModel中对我的File属性进行客户端验证(MaxLength将是用户可以上传的文件数),我该怎么做?
或者,是否有其他推荐的方法在mvc4中执行此文件上传类型的模式?