带有绝对 URL 的 Html.BeginForm()? [英] Html.BeginForm() with an absolute URL?

查看:24
本文介绍了带有绝对 URL 的 Html.BeginForm()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 POST 操作设为绝对 URL(例如,http://www.cnn.com).有没有办法使用 Html.BeginForm() 助手并将其传递给 url?

I need to have the POST action be to an absolute URL (e.g., http://www.cnn.com). Is there a way to use Html.BeginForm() helper and pass it the url?

推荐答案

BeginForm 方法有几个重载.为了使用所需的 url 设置表单标签上的 action 属性,您需要使用以下 BeginForm 的重载:

BeginForm method has several overloads. In order to set the action attribute on the form tag with the desired url, you need to use following overload of BeginForm:

BeginForm(String, String, FormMethod, IDictionary<String, Object>)
// here are the parameter names:
BeginForm(actionName, controllerName, method, htmlAttributes)

既然要发布到外部站点,则无需设置actionName和controllerName,只需将它们保留为空即可.

Since you want to post to an external site, there is no need to set actionName and controllerName, just leave them as null.

@Html.BeginForm(
   null, null, FormMethod.Post, new {@action="http://cnn.com/post"}
)

这不会对动作参数进行编码.

This will not encode the action parameter.

这篇关于带有绝对 URL 的 Html.BeginForm()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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