I am using ASP.NET MVC 4 application, I need to Display messages in the Client, by sending messages from Controller to Client.
My requirement is user click a button in UI and i will process the files on the server and Display message in UI on end of each foreach file i process. i need to show the File names in the Client Using ASP.NET MVC.
Can any one Help how to show the messages in the Client by calling client method from server on for-each loop each time.
I am able to call the controller and end of each controller I am sending final message to UI, but how to send on each foreach loop iteration?
Try this: Script method to update progress based on predefined interval you want
Controller:
View:
Start new task …
You have to write an
ActionResult
that progressively write result to the response. so you can show the user some data in every foreach loop iteration. I have written a simpleActionResult
that writes a number every 2 seconds:and this is an action that returns this result:
So you can write an
ActionResult
and write yourforeach
code inExecuteResult
method.UPDATE:
You can make this call with an Ajax request and return result with a simple code like the following code: