Solved

Performance  Html.BeginForm vs jQuery

Posted on 2016-12-01
3
67 Views
Last Modified: 2017-01-17
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 55

Expert Comment

by:Julian Hansen
ID: 41908481
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
ID: 41908493
How can I implement AntiForgeryToken and ValidationMessageFor using jQuery? Do you have a sample ?
0
 
LVL 55

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41908594
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

830 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