有没有办法让 Ajax.BeginForm 输出绝对 url 而不仅仅是相对 url?
我正在尝试在另一台服务器上托管的站点上使用 CORS 处理一些表单。 目前,我正在使用 ajax 选项中的 jquery onsuccess 解析表单。
我没有任何关于编写扩展的教程的指针,因为它会很方便
最佳答案
Is there any way to get the Ajax.BeginForm to output a absolute url rather than just a relative one?
是的,但您需要在 AjaxOptions
中指定 Url
并且不使用采取操作和 Controller 名称的重载:
@using (Ajax.BeginForm(new AjaxOptions { Url = Url.Action("Foo", "Bar", null, "http") }))
{
...
}
Url.Action
有一个重载,您可以在其中指定要使用的生成绝对 url 的协议(protocol)。如果您想使用与用于请求当前操作的协议(protocol)相同的协议(protocol)而不是对其进行硬编码,您可以使用以下内容:
@using (Ajax.BeginForm(new AjaxOptions { Url = Url.Action("Foo", "Bar", null, Request.Url.Scheme) }))
{
...
}
关于c# - Ajax.BeginForm 绝对 url MVC CORS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17965171/