asp.net mvc - How to let user know the resume they are submitting is too large -
My cshtml file to upload, where will this file go to javascript?
@ {ViewBag.Title = "Upload"; } & Lt; Div id = "progressbar" & gt; & Lt; Div id = "progressbar" class = "all" style = "width: 20%"> gt; & Lt; / Span & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "jambotron" & gt; & Lt; H2 & gt; Job Application Management System & lt; / H2 & gt; & Lt; P class = "lead 2" & gt; Welcome @ ((string) (ViewData ["FullName"]), please upload your resume here. Thanks! & Lt; / P & gt; @Usage (HTML.businessforms (empty, empty, formmath.past, new {enctype = "multipart / form-data"})) {& lt; Table & gt; & Lt; TR & gt; & Lt; TD & gt; & Lt; Label & gt; & Amp; Nbsp; & Lt; / Labels & gt; & Lt; Input type = "file" class = "btn btn-default" name = "file" id = "file" /> gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> & Lt; Input type = "submit" class = "btn btn-default" id = "upload" value = "upload" gt; & Lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt; If (TempData ["notice"] = null) {& lt; P & gt; @TempData ["Notice"] & lt; / P & gt; & Lt; P & gt; & Lt; Button class = "btn btn-default" onclick = "location.href = '@ Url.Action (" create "," execution ");' return false; ' & Gt; Continue to the findings & lt; / Button & gt; & Lt; / P & gt; }}
This is my working code that shows how to start a resume and how to save it using asp.net mvc how do I tell that the file's The size is too large if the user submits a file that can not be operated. Right now, if a user submits a file too large, then they take them to an error page. I just want to do something on a popup or screen that asks them to submit a short file Thank you!
if (resume.File.ContentLength> gt; {string fileName = path. GetFileName (resume.File.FileName); String path = path. Combine (server.mappath ("~ / content / resume"), filename); Resume.File.SaveAs (Path); } TempData ["Notice"] = "Added resume:" + resume.File.FileName; See Return (Resume); } Hold (exception) {ViewBag.Message = "upload error"; See Return ("Upload"); }}
You can do it with a simple javascript:
< Pre> & lt; Script type = "text / javascript" & gt; $ ('# Image-file') ('Change', function () {var filesize = this.files [0]. Size / 1024/1024). Fix (2) + "MB"); // can now use the filesize variable and check it's price and show pop}}; & Lt; / Script & gt;
Or you can use it:
GetFileSize (fileid) function {try {var fileSize = 0; // If IE ($ .browser.msie) {// Before creating an object of ActiveXObject, please ensure that ActiveX is active in your IE browser objFSO = New ActiveXObject ("Scripting.FileSystemObject"); Var filePath = $ ("#" + fileid) [0]. value; Var objFile = objFSO.getFile (filePath); Var fileSize = objFile.size; // size in KB file size = file size / 1048576; // FF, Safari, Opera, and others other than {fileSize = $ ("#" + fileid) [0]). File [0]. Size // This will calculate the file size / put your warning or validation message here}} hold (e) {warning ("error:" + e); }}
Or you can submit the file size as:
& lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ ('# upload'). ('Click', function (e) {e.PreventDefault ()) var filesize = $ ("# file"). Files [0] .size / 1024/1024) .toFixed (2)); // File MB can now use the filesize variable and check it if the value and show pop (parciet (files)> 3) {warning ("file is too large"); Return false; } And {$ ("form"). Submit (); }}); }); & Lt; / Script & gt;
Comments
Post a Comment