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.

4
  • 2
    The word you need to know is Ajax. Commented Jun 4, 2014 at 11:28
  • Investigate calling Web API services with jQuery/javascript Commented Jun 4, 2014 at 11:28
  • Thank you everyone, I shall begin investigation. Commented Jun 4, 2014 at 11:31
  • 1
    possible duplicate of Calling ASP.NET MVC Action Methods from JavaScript Commented Jun 4, 2014 at 11:33

1 Answer 1

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();
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

This is a perfect reference along with what DontVoteMeDown said. Thank you very much!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.