Html.BeginForm()与绝对URL? [英] Html.BeginForm() with an absolute URL?

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

问题描述

我需要有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方法有几个重载。
为了设置action属性与所需的URL的形式标记,你需要使用以下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"}
)

这不会带code中的操作参数。

This will not encode the action parameter.

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

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