Ajax.BeginForm绝对网址MVC CORS [英] Ajax.BeginForm absolute url MVC CORS

查看:93
本文介绍了Ajax.BeginForm绝对网址MVC CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法让Ajax.BeginForm输出一个绝对的URL而不是一个相对的URL?

Is there any way to get the Ajax.BeginForm to output a absolute url rather than just a relative one?

我正在尝试在托管在另一台服务器上的站点上使用某些形式的CORS. 目前,我正在用ajax选项中的jquery onsuccess解析表单.

I am trying to get some forms working with CORS on a site hosted on another server. At the moment I am parsing the form with jquery onsuccess in the ajax options.

对于编写扩展程序的教程,我没有任何指示,因为它很方便

I am not any pointers to a tutorial on writing an extension for it would be handy

推荐答案

是否有任何方法可以获取Ajax.BeginForm以输出绝对URL 而不只是亲戚?

Is there any way to get the Ajax.BeginForm to output a absolute url rather than just a relative one?

是的,但是您需要在AjaxOptions中指定Url,而不要使用具有操作和控制器名称的重载:

Yes, but you need to specify the Url in the AjaxOptions and not use the overload which takes action and controller names:

@using (Ajax.BeginForm(new AjaxOptions { Url = Url.Action("Foo", "Bar", null, "http") }))
{
    ...
}

Url.Action有一个重载,您可以在其中指定要使用的生成绝对URL的协议.而且,如果您要使用与请求当前操作所用的协议相同的协议,而不是对其进行硬编码,则可以使用以下协议:

Url.Action has an overload where you could specify the protocol to be used which generates absolute urls. And if you wanted to use the same protocol as the one used to request the current action instead of hardcoding it you could use the following:

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

这篇关于Ajax.BeginForm绝对网址MVC CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆