Book Image

Mastering ASP.NET Core 2.0

By : Ricardo Peres
Book Image

Mastering ASP.NET Core 2.0

By: Ricardo Peres

Overview of this book

<p>ASP.NET is an open source web framework that builds modern web apps and services. This book is your one-stop guide to the new features of ASP.NET Core 2.0, including web APIs and MVC. We begin with a brief overview of the basics, taking you through the MVC pattern, platforms, dependencies, and frameworks. We then move on to setting up and configuring the MVC environment before talking about routing and advanced routing options. Next, we'll look at model binding, controllers and actions, filters, user authentication, and testing.</p> <p>Moving on, you’ll learn about all the aspects of syntax and processes when working with Razor. You’ll be introduced to client-side development and will get to know about the security aspects of ASP.NET Core. We will also look at Microservices with ASP.NET Core. Finally, you’ll find out how to deploy ASP.NET Core to new environments such as Azure, AWS, and Docker. By the end of the book, you will be well versed with development in ASP.NET Core and will have a deep understanding of how to interact with the framework and work cross-platform.</p>
Table of Contents (23 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

AJAX


AJAX is a term coined long ago to represent a feature of modern browsers by which asynchronous HTTP requests can be done, via JavaScript, by the browser, without a full page reload.

ASP.NET Core does not offer any support for AJAX, which doesn't mean that you can't use it--it is just the case that you need to do it manually.

This example uses jQuery to retrieve values in the form and send them to an action. Make sure the jQuery library is included in either the view file or the layout:

$('#submit').click(function(evt) {
  evt.preventDefault();

  var payload = $('form').serialize();

  $.ajax({
    url: '@Url.Action("Save", "Repository")',
     type: 'POST',
     data: payload,
     success: function (result) {
       //success
     },
     error: function (error) {
       //error
     }
  });
});

This bit of JavaScript code does a couple of things:

  1. Binds a click event handler to an HTML element with an ID of submit.
  2. Serializes all form elements.
  3. Creates a POST AJAX request to a controller...