MVC4 Ajax表单URL [英] MVC4 Ajax Form URL
问题描述
是否可以为 asp.net-mvc-4 AJAX格式?我正在寻找使用Ajax.BeginForm()
语法的答案,以便我可以利用Microsoft的模型构造魔术,而无需自己重新解析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.
在foo.com.au/getFoo
上存在一个局部视图,其中包含ajax形式. ajax表单将发布到Foo
控制器(默认),getFoo
操作.
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.
当我从外部站点(bar.com.au
)拨打此电话时,我希望它回发到foo.com.au/getFoo
.而是将其发布到bar.com.au/getFoo
.有什么方法可以告诉Ajax表单发布到完整的URL,而不仅仅是相对路径?
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?
动机
对于那些怀疑hax0rz或其他犯规行为的人,我构建了一个小部件,该小部件已集成到多个客户端站点中.我现在正在为此小部件构建一个身份验证插件.该小部件不会将它们重定向到我的网站进行身份验证,因此我希望它将用户名/密码输入表单的结果发送回我的域.
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.
推荐答案
您需要通过Ajax-options传递它,而不是在BeginForm的上方提供它:
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)
}))
{
...
}
这篇关于MVC4 Ajax表单URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!