c# - MVC4 Call back from server to client -


i using asp.net mvc 4 application, need display messages in client, sending messages controller client.

i need upload file server , processing in foreach loop , once each foreach need display message in ui. have loop need send message server client on each loop in case

view

@using (html.beginform("index", "home", formmethod.post, new { id = "formupload", enctype = "multipart/form-data" })) {     <div>         <b>upload file</b>         <input type="file" name="file" />         <input type="submit" value="upload file" name="btnupload" onclick="progressstatus();"/><br />     </div>     <div>         @viewbag.message     </div>     <div style="width: 30%; margin: 0 auto;">         <div id="progressbar" style="width: 300px; height: 15px"></div>         <br />     </div> } 

controller code

[httppost] public actionresult index(httppostedfilebase file) {     if (file != null)     {         var fname = path.getfilename(file.filename);         var exis = path.combine(system.web.httpcontext.current.server.mappath("~/storage/uploads"), fname);         if (system.io.file.exists(exis))         {             viewdata["message"] = "the file " + fname + " has exists";         }         else         {             try             {                 if (file.contentlength > 0)                 {                     var filename = path.getfilename(file.filename);                     var folderpath = server.mappath("~/storage/uploads");                     fname = filename;                     var path = path.combine(folderpath, filename);                     var filebytes = new byte[file.contentlength];                     if (!directory.exists(folderpath))                         directory.createdirectory(folderpath);                     file.saveas(path);                     (int = 0; < 20; i++)                     {                         //display message in ui here each time runs want show user message 1,2,3,4 etc each time runs                     }                 }                 viewdata["message"] = "the file " + fname + " has uploaded successully";             }             catch (exception e)             {                 viewdata["message"] = "the file " + fname + " not upload";                 viewdata["message"] = e.message;             }         }     }     else         viewdata["message"] = "please choose file";                 return view(); } 

you can create dictionary key value pair in each iteration of loop

for (int = 0; < 20; i++)                 {                     viewdata["message_"+i.tostring()] = //your message;                 } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -