0

I'm creating an API in MVC using C# for the back end of the API, and the standard HTML and JavaScript for the front end. My question is how do I reference the functions that I made in C# by using JavaScript in the front end?

I am new to HTML and JavaScript, so any help or references at all would greatly be appreciated. Thank you.

1 Answers1

1

Example using jQuery Ajax:

    $.ajax({
        type: "POST",
        url: "/MyController/MyAction",
        headers: { "cache-control": "no-cache" },
        contentType: 'application/json',
        data: JSON.stringify({ param: myParameter }),
        success: function (result) {

        },
        failure: function (error) {
        }
    });

C#

public class MyController: Controller
{
    public ActionResult MyAction(string param)
    {
        return View();
    }
}
Marcus
  • 8,230
  • 11
  • 61
  • 88