2

So we are pretty new to ASP.Net MVC

We have this method that runs when we click on a button in our view. We would like to send the date string to our controller. How can we achieve this?

$('#calendar').fullCalendar({
        //weekends : false

        dayClick: function(date) {

            console.log(date.format());

        }
    })

This is our controller

   [HttpPost]
    public IActionResult Booking(string test)
    {
        var booking = new Booking();

        //booking.Date = dateTime;

        Console.WriteLine(test);

        var viewModel = new BookingsideViewModel
        {
            Subjects = new[] {"Matematik", "Dansk", "Engelsk"},
            Booking = booking
        };

        return View();

    }

1 Answer 1

3

you can do it using ajax call,

$.ajax({
        url: '@Url.Action("Booking")',
        data: { 'test' : date },
        type: "post",
        cache: false,
        success: function (response) {
            console.log("success");
        },
        error: function (error) {
            console.log(error.message);
        }
    });

you can also write url like this:

url:"/ControllerName/ActionName"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.