Html.BeginForm() with an absolute URL?

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)

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.

Leave a Comment