Solved

Performance  Html.BeginForm vs jQuery

Posted on 2016-12-01
3
4 Views
Last Modified: 2016-12-01
There are any gain of performance or other advantages to do my POST request using ajax jQuery instead of do this requests using Html.BeginForm with a button to submit this request to server?
0
Comment
Question by:berechit
  • 2
3 Comments
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
AJAX is to do background operations without refreshing the page. The question on what to use is around usability - not performance.

If you are going to stay on the same page but need to send (and receive) data from the server then AJAX is the way you do it. If you are going to end up re-rendering the page after sending data to the server then there is not much motivation for using AJAX
0
 

Author Comment

by:berechit
Comment Utility
How can I implement AntiForgeryToken and ValidationMessageFor using jQuery? Do you have a sample ?
0
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
Comment Utility
Why would you want to use jQuery for that?

If you are trying to prevent a CSRF you need to generate the token on the server and validate it on the server.

If you want to do an AJAX call and pass the token then you can included it the request by doing something like this
$(function() {
   $('element-that-triggers-ajax').click(function() {
         var csrftoken = $('input[name="__RequestVerificationToken"]').val();
         var data = {
              // your data here
              __RequestVerificationToken: csrftoken
         };
         $.ajax({
              url: '/path/to/svc',
              data: data,
              type: 'POST'
         }).then(function(resp) {
             // process return
         });
   });
});

Open in new window

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now