Nirav Solanki
Nirav Solanki

Reputation: 89

How to set jquery variable value to Viewbag or ViewData

I will try to make button click event using jquery. but I do not know way how I can pass jquery variable value in Viewbag or ViewData

Upvotes: 0

Views: 5483

Answers (1)

Michał
Michał

Reputation: 2494

In general handling click event is solved by .click(function()) method or .on('click', function()). After handling the click event and then sending a http POST/GET request to pass the data to your server-side application.

Example snippet would look like:

$('#button-id').click(function(){
    // Click handle 
    $.post("/url/to/controller", $( "#form-id" ).serialize() ); // send data to controller
});

And then handle the input in the controller.

Upvotes: 1

Related Questions