Probs with ASP.NET MVC Postback + Callback Synchronously - asp.net-mvc

I am trying to create an upload control for ASP.NET MVC with jQuery progress bar. In ASP.NET the implementation works no problems, but in MVC the problem is that the server doesn't respond to my callbacks until the file is uploaded.
The upload control is based on html file upload element, and I cannot for the life of me, understand how MVC handles postback + callback synchronously ?
I have searched for a whole bunch of answers, but all I can find is a "callback+callback" solution and NOT a postback+callback.
Does anyone have any idea how to solve this problem for MVC ?
Thanks

Hrmmm,
Thomas, MVC does not handle post-backs at all. Because a URL is directly routed to an Action method on a controller, a form is not meant to actually post-back to itself. Further more, all of the post back processing that Asp.Net had to handle post-backs on the server was pulled out of the .Net MVC framework.
A better approach to accomplish what you're trying to do with a progress bar would be to use JQuery with AJAX to make the call to your server and then use Javascript/CSS (possibly a lightbox approach) or a pop-up window to inform the user that they are waiting. When the Ajax call completes it's work, you can have Javascript fire the redirect to the page in your MVC that you want the user to be redirected to after the action has been performed. Making AJAX calls with JQuery is a total breeze and is pretty fun to play around with as well!
Check it...

Suggestion:
You can use the JQuery Uploadify control to show the status of
the upload. This control has a flash and html 5 type controls. Use whichever is applicable to you.

Related

Do a full non-ajax post from a partial view in asp.net mvc

This more of an out of interest question than an urgently need an answer one, but I have been trying to find a good example of how to deal with a full postback from a partial view in asp.net MVC. The obvious example is the case where you have a small login form on every page. You can easily accomplish this through an asynchronous post back using jquery, but I am wondering if there is a way to do it without the use of javascript. I know it may be pedantic, but I don't like the idea of assuming the client has javascript enabled, particularly in this day and age where responsive design/ progressive enhacements are the big buzzwords around, so having you log in tied to javascript means that anyone on a simple mobile device won't be able to use it since their device probably won't support it.
Anyone have any ideas / examples of how to accomplish this? It's such a simple thing to implement in web forms I can't believe it's as tricky as I've heard it made out to be in MVC.
You just need a form within the view, that's all. The form will POST to its controller action method and generate a full page refresh (if that's what you mean by a full postback - I guess it is) irrespective of whether its a partial or not.
You can have multiple forms on a MVC view, and each one of them will give you a full page refresh, whereas with WebForms the pattern was one main form per page.

How Can We get the Values of the Form without Post in asp.net MVC?

I Have Make a Create Form.
& I want the Values in Controller how can I get them Without Postback the Whole Page?
Any article please help
You could use AJAX to send the form values to a controller action. The jQuery Form plugin is very good for this purpose. The plugin reads all the form values and sends them in an AJAX request to a controller action for processing.
Use javascript to call a web service (i.e ajax). Check out this article for some basics.
Since you're using the "postback" term I think you might be coming from a WebForms background which hides all the HTTP request-response cycle. POSTs are done on <form>s, so technically the entire page is not "posted back", but the data from the form in which the pressed resides.

UpdatePanelAnimation helper in asp.net mvc

I need to create a helper function for UpdatePanelAnimation extender from AjaxControlToolkit in asp.net mvc. I downloaded the toolkit and loaded the js files into my project.
Can someone please tell me how should I write this helper function and what all parameters are to be passed into it.
I am new to asp.net and mvc
thanks for the reply. but we have to include more helper functions in mvc in the near future. so i need to implement this anyway.
Since you have jQuery, using UpdatePanel and UpdatePanelAnimation is not desired in ASP.NET MVC. You can use jQuery Animate method:
http://jqueryui.com/demos/animate/#source
First you call animate to hide panel, then you use post or get ajax method and in callback you call animate to come back to previous state. If you do it properly, it will look like UpdatePanelAnimation and have very nice looking code.

ASP.NET MVC & Silverlight - fire an event in both with one button?

I currently have a little form with a silverlight bit for a person to sign their name and I was wondering if there was a way to have the submit button post to the controller and a silverlight code behind action... I tried adding a dom event to fire silverlight code but I guess that doesn't fire both events...
Any ideas?
You can have Silverlight make calls back out to the DOM:
Calling Javascript functions from Silverlight (Example is Silverlight 2)
Using that method, you can have your Silverlight app complete its logic and then call back in to the page to complete the page postback logic.

Please wait page in ASP.NET MVC

A page executes a number of tasks and takes a long time to process. We want to give the user feedback as each task is completed.
In ASP.NET webforms we used Response.Flush()
What way would you a approach this in ASP.NET MVC?
You can still use Response.Write() and Response.Flush() for whatever status you want to send down the wire. Or if you have your progress thingy in a user-control, you could do something like:
this.PartialView("Progress").ExecuteResult(this.ControllerContext);
this.Response.Flush();
from your controller while doing your lengthy operation in the controller's action method.
It's up to you to choose this or the client-side approach as mentioned in the comments here, just wanted to point out that server-side is still possible.
I would suggest to use AJAX for displaying progress. See links for ideas:
Real-Time Progress Bar With ASP.NET AJAX
Using jQuery Plugins with ASP.NET
Ajax Progress Bar Control
There are two basic ways:
Poll a server page that returns the status, then once the operation is done, redirects to a results page. MVC is nothing to do with this way, you'd need to use a server variable to store objects/status - this is a way that's more relevant to a standard Asp.NET application as you're (presumably) using session variables etc. anyway.
AJAX call from the client to a webservice on the server. Asp.NET MVC is going to be rolling the jQuery framework in, so use that for the client call and event handling for the response. This would be more in the spirit of MVC which doesn't/shouldn't use session state etc.
Me personally I would consider two optoins:
redirect to wait page(s), then fire actions
Do it ajax style
You can make it in client side. In each step, you set some session variable with the current step. Then, You make another action in your controller say called: "GetProgress" and assign a view and URI for it.
In the action, you will check this session and return the current progress of your task. In the client side, make a timer (i.e setTimeOut) and you invoke the URI of the later controller action every specific amount of time - 1 second or so. That is it.

Resources