Been new to VB .Net MVC (v5.0) and Razor (v3.0) I've made my way so far through the subtlety of out of the box client side unobtrusive validation tools.
But now I guess I need to go custom as I can't find anywhere a straightforward solution to my problem.
So here is the ViewModel that is concerned :
Public Class ContactViewModel
<Required>
Public Property MailAddress As String
<Required>
Public Property MailObject As String
<Required>
Public Property MailBody As String
<AllowedFileExtentions("doc", "docx", "xls", "png", "jpeg", "pdf", "xlsx", "odt")>
<MaxTotalFileSize(1024 * 1024 * 10, "Total file size exceeded authorised limit of 10 Mo")>
<MaxFileSize(1024 * 1024 * 5)>
Public Property AttachementFiles As List(Of HttpPostedFileBase)
End Class
As you can see, I've already written (but not yet tested) custom validation attributes for the AttachementFiles
property according to this blog. The goal of each of those attributes should be obvious according to there names ;)
My trouble here is that I was on my way to implement the corresponding client side javascript code rules when I've noticed I had no clues how to have .Net MVC integrating everything all together in a smooth way.
Which helper function should I call in my view in order to have an <input type="file" multiple/>
generated with the right data-val-
attributes for the unobtrusive part ?
I remember seeing here and there it should be possible to define custom template for List(Of HttpPostedFileBase)
type in order to have EditorFor
helper generating what I want, but I can't help wondering if there is not a better (simpler in fact :)) way to achieve that.
Are they helper functions existing (according to my MVC / Razor version constraints) that would spare me the writing of the custom template ?
If there isn't, what is your advise in order to be as code straightforward as possible ?
Please notice : I'm aware that such validation on client side (file size and extension) is dependent on browser capabilities, but I'm fine with it and my real concern is the way to glue everything together with the least effort possible (after all, a good dev is lazy by nature ;))
Thanks in advance for any help !