Reputation: 11725
Quite some time i`ve learnt MVC. I have seen various techniques to post data :ajax post and form post.
Is there any other?
I`m quite confused about which technique to use and when?
Can anyone help me on this part?
Upvotes: 0
Views: 130
Reputation: 2861
The PRG pattern sounds nice but I really dislike having to put the received values in TEMPDATA.
Upvotes: 0
Reputation: 1593
Well, all ways you described above are serving to send the data from your html form to the server for processing.
You were right, you may send this data via form post or ajax post.
The difference is simple.
When you are doing form post, your browser is collecting all parameters from your form and sending it to the server. While the browser waits for the response, it hangs any activity for the page. After that, the page is blinking and reloading its content.
All that period of time, the consumer of your site feels that he should sit and wait for some time until the window blink and reload its content.
Ajax post does the same as the form post. It collects the data from the page and then sends it to the server. The main difference, this way does not hangs your browser window. In this way your application works like windows application. Things are opening, closing, the data is changing, etc. This way requires of using some script language like javascript or vbscript. At present moment there is a lot of javascript libraries that helps you. For example, you may use jquery library
So, since there is no difference, its up to you which way to use.
I would recommend to always use firstly form post, because it does not requires any client scripting and its easier to implement. When you be sure that your application is working in the way you want,you may add some good looking things like ajax posts, so your application will look more friendly to the consumer
Upvotes: 2
Reputation: 3718
A form does an HTTP Post request back to the server. I'd suggest to use 'Post, Redirect, Get' Pattern. Take a look at this article: http://www.eworldui.net/blog/post/2008/05/ASPNET-MVC---Using-Post2c-Redirect2c-Get-Pattern.aspx
Upvotes: 0