I need to know how can I pass the additional data to mvc action with Ajax.BeginForm? I did not find any Ajax Option to pass additional params like we can pass when we use $.ajax. Can someone please suggest how can I pass it?
1 Answer
Try this
@using(Ajax.BeginForm("Action", "Controller", new AjaxOptions { /*OPTIONS for example*/ HttpMethod = "POST", UpdateTargetId = "ajaxCreateAdminForm" }))
{
//Form with inputs
}
AjaxOptions have many opt. which you can use. In this page you can check this: MSDN page
EDIT
@using(Ajax.BeginForm("Action", "Controller", new { name="test" }, new AjaxOptions { /*OPTIONS for example*/ HttpMethod = "POST", UpdateTargetId = "ajaxCreateAdminForm" }))
{
//Form with inputs
}
All types of helper Ajax.BeginForm calls are describe in MSDN ->Ajax.BeginForm
5 Comments
Ammar Khan
I want something similar to this data:"{'name': test}", how would I pass data parameter to mvc action
Damian S
If I understand you, You dont want use AjaxOptions to customise ajax form. You only want send extra date to action in controller and you of course can :)
Ammar Khan
Yes, right. Please let me know how would I do that with ajax.beginform ?
Damian S
I put this in my anwer, under EDIT label. :)
chiapa
Here you are sending "name=test", static data that you know when you are writing the code, but what if you want to send something from an input, how to include that as an extra parameter?