3

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 1

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

I want something similar to this data:"{'name': test}", how would I pass data parameter to mvc action
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 :)
Yes, right. Please let me know how would I do that with ajax.beginform ?
I put this in my anwer, under EDIT label. :)
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?

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.