0

我正在尝试发布外部 URL,例如。(www.msn.com) 按下提交按钮。但是当我这样做时,我的验证都不起作用......它只是在我的外部 url 2 中输入没有任何数据的条目。当我按下提交时它也不会进入控制器按钮。我不知道我是不是做错了什么...

这是我的视图代码:

@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">&nbsp;</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."; }
        }

    }
4

2 回答 2

1

它完全按照你的吩咐去做。

HTML标记向属性<form>中的 URL 发送 POST 请求。action

Html.BeginForm()创建一个带有指向您的控制器<form>的属性的标签。action

当您action显式设置属性时,您将替换 MVC 中的值并使其直接转到该 URL。

于 2013-02-08T17:29:24.793 回答
0

如果您想在发布到另一个网站之前在服务器端对您的数据做一些事情,请删除该action属性,以便您发布到与开始时相同的 URL。在处理POST此表单并进行验证的操作中,准备您的数据。准备好后,使用WebRequest 类使用方法将此数据发送到另一个网站POST

于 2013-02-08T18:05:00.443 回答