<head> <title>Index</title> <style type="text/css"> #statusBorder { position:relative; height:5px; width:100px; border:solid 1px gray; display:none; } #statusFill{ position:absolute; top:0; left:0; width:0px; background-color:Blue; height:5px; } </style> <script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script> <script type="text/javascript"> var uniqueId = " @Guid.NewGuid().ToString()"; $(document).ready(function (event) { $('#startProcess').click(function () { $.post("Home/StartLongRunningProcess",{ id: uniqueId }, function (data) { if (data = "null") { alert("文件為空!"); } else { $('#statusBorder').show(); getStatus(); } }, "multipart/form-data"); event.preventDefault; }); }); function getStatus() { var url = 'Home/GetCurrentProgress/' + uniqueId; $.get(url, function (data) { if (data != "100") { $('#status').html(data); $('#statusFill').width(data); window.setTimeout("getStatus()", 100); } else { $('#status').html("Done"); $('#statusBorder').hide(); alert("文件保存成功"); }; }); } </script> </head> <body> <div> <div id="status"> </div> <h2>@Html.Encode(ViewData["Message"]) </h2> <div> <input id="File1" type="file" name="file" /> <input id="startProcess" type="submit" value="提交" /> </div> <br /> <div id="statusBorder"> <div id="statusFill"> </div> </div> </div> </body> </html>