asp.net mvc - Custom validation of HttpPostedFileBase -


i use mvc5. i've got issue file uploading using httppostedfilebase. i've got form can can choose file disk , type information it(in textbox). when submit form controller action called. in action open file , check if has specific data(related data textbox). validation here. can't using jquery - it's complex. server side validation option. if validation fails return model(with file) view after i've got validation error next file field file field empty. i've read that's hard return file view. don't want use ajax upload file. want simple. if got article can help, please share me.

how can solve problem?

i know mentioned not using ajax file upload, think solution simple one.

using following jquery plugin (https://blueimp.github.io/jquery-file-upload/), can automate process , if there validation issues in file, can return following model error.

string errors = "errors returned complex logic"; if (!string.isnullorempty(errors)) {     // error response     status = new viewdatauploadfilesresult()     {         name = path.getfilename(hpf.filename),         size = hpf.contentlength,         error = errors     }; } 

here class needed response matches jquery file upload documentation: https://github.com/blueimp/jquery-file-upload/wiki/setup

public class viewdatauploadfilesresult {     public string name { get; set; }     public int size { get; set; }     public string type { get; set; }     public string url { get; set; }     public string error { get; set; } } 

if i'm understanding correctly, since file on users computer, need associate file current file they're attempting upload returns errors. , make don't have reselect file upload. don't see other reason need return actual file user have file they're uploading.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -