David Colwell
David Colwell

Reputation: 2590

MVC4 Ajax Form URL

Is there a way to set the URL for an AJAX form? I am looking for an answer using the Ajax.BeginForm() syntax so that i can make use of Microsoft's model construction sorcery without needing to re-parse the url string myself.

There is a partial view that lives on foo.com.au/getFoo which has an ajax form in it. the ajax form will post to Foo controller (default), getFoo action.

When i am calling this from an external site (bar.com.au) i want it to post back to foo.com.au/getFoo. Instead it is posting to bar.com.au/getFoo. Is there some way to tell the Ajax Form to post to the full URL instead of just the relative path?

Motive
For those of you who suspect hax0rz or other foul play, i have built a widget which is being integrated across multiple client sites. I am now building an authentication plugin for this widget. The widget does not redirect them to my website for authentication, therefore i want it to post back to my domain with the results of the username/password input form.

Upvotes: 6

Views: 1449

Answers (1)

Kenneth
Kenneth

Reputation: 28737

You need to pass it in through the Ajax-options instead of supplying it in the overloaad of BeginForm:

@using (Ajax.BeginForm(
    new AjaxOptions
    {
        Url = Url.Action("getFoo", "Foo", null, Request.Url.Scheme)
    }))
{
    ...
}

Upvotes: 2

Related Questions