Reputation: 13616
I need to pass data from this razor page view:
To this action method:
I want my data being sent to an action on page load.
How to implement this?
Upvotes: 0
Views: 807
Reputation: 44600
I would use Ajax & jQuery to push data to the server:
$(function() { // on page load
$.post({ //do ajax post request
url: '/OauthCallBack/GmailOAuthCallback',
data: 'code=' + someCode, //your data
success: function () {
//Success callback if necessary
}
})
});
public class OauthCallBackController : Controller
{
[HttpPost]
public ActionResult GmailOAuthCallback(string code)
{
//Do something
return new EmptyResult(); //or return anything :)
}
}
Upvotes: 2