0

たとえば、外部URLを投稿しようとしています。(www.msn.com)送信ボタンを押したとき。しかし、それを行うと、検証が機能しません...外部URLにデータなしでエントリを作成するだけですボタン。悪いことをしているかどうかはわかりません...

ビューのコードは次のとおりです。

@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 に答える