我正在尝试发布外部网址,例如。 (www.msn.com)按下提交按钮。但是当我这样做时,我的任何一个都没有工作......它只是在我的外部网址中没有任何数据的条目 2.当我按下提交按钮时,它也不会进入控制器。 我不知道我做错了什么......
以下是我的View代码:
@model n.Models.PopupDemoModel
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm("Demo","Home", FormMethod.Post, new { @action = "https://www.msn.com?encoding=UTF-8/post" }))
{
@Html.ValidationSummary(true)
<fieldset>
<input type=hidden name="oid" value="">
<input type=hidden name="retURL" value = "test" />
<input type="hidden" name="debug" value=1 />
<input type="hidden" name="debugEmail" value = "a@test.com" />
<div class="editor-label grid_2">
@Html.LabelFor(model => model.first_name)
</div>
<div class="editor-field grid_3">
@Html.TextBoxFor(model => model.first_name, new { @class = "demo-field-longer" })
</div>
<div class="grid_3 error long" style="margin-left:250px">
@Html.ValidationMessageFor(model => model.first_name)
</div>
<div class="clear"></div>
<div class="editor-label grid_2">
@Html.LabelFor(model => model.email)
</div>
<div class="editor-field grid_3">
@Html.TextBoxFor(model => model.email, new { @class = "demo-field-longer" })
</div>
<div class="grid_3 error long" style="margin-left:250px">
@Html.ValidationMessageFor(model => model.email)
</div>
<div class="clear"></div>
<div class="editor-label grid_2">
@Html.LabelFor(model => model.phone)
</div>
<div class="editor-field grid_3">
@Html.TextBoxFor(model => model.phone, new { @class = "demo-field-longer" })
</div>
<div class="grid_3 error long" style="margin-left:250px">
@Html.ValidationMessageFor(model => model.phone)
</div>
<div class="clear"></div>
<div class="editor-label grid_2">
@Html.LabelFor(model => model.company)
</div>
<div class="editor-field grid_3">
@Html.TextBoxFor(model => model.company, new { @class = "demo-field-longer" })
</div>
<div class="grid_3 error long" style="margin-left:250px">
@Html.ValidationMessageFor(model => model.company)
</div>
<div class="clear"></div>
<div class="clear"></div>
<div class="grid_2 sub-spacer"> </div>
<div class="editor-field grid_2 submit">
<input type="submit" value="Submit" id="demo-submit-button"/><br />
@ViewData["DemoMessage"]
</div>
</fieldset>
这是我的模特:
public class PopupDemoModel
{
[Required]
[Email]
[DisplayName("Email address")]
public string email { get; set; }
[Required]
[DisplayName("Phone number")]
public string phone { get; set; }
[Required]
[DisplayName("Contact name")]
public string first_name { get; set; }
[Required]
[DisplayName("Company name")]
public string company { get; set; }
public string MessageSent
{
get { return "We'll contact you shortly."; }
}
}
答案 0 :(得分:1)
这正是你告诉它的。
HTML <form>
标记向action
属性中的网址发送POST请求。
Html.BeginForm()
创建一个<form>
标记,其中action
属性指向您的控制器。
当您明确设置action
属性时,您将替换MVC中的值并使其直接转到该URL。
答案 1 :(得分:0)
如果您希望在发布到其他网站之前对服务器端的数据执行某些操作,请删除action
属性,以便您将发布到与开始时相同的URL。在处理此表单中的POST
并执行验证的操作中,准备您的数据。准备就绪后,使用WebRequest class使用POST
方法将此数据发送到其他网站。