Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC4 Ajax Form URL

Is there a way to set the URL for an asp.net-mvc-4 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.

like image 861
David Colwell Avatar asked Aug 19 '13 03:08

David Colwell


1 Answers

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)
    }))
{
    ...
}
like image 131
Kenneth Avatar answered Nov 04 '22 16:11

Kenneth