2013-02-08 17 views
0

我嘗試後外部URL如工作。 (www.msn.com)上提交button.But當我這樣做沒有我的valdation的作品...它只是讓沒有任何數據的標題在我的外部URL 2.也是它不會當我按到控制器按提交按鈕。 我不知道如果我做錯什麼......驗證停在使用formmethod.post

這裏是我的代碼查看:

@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 = "[email protected]" /> 

    <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."; } 
     } 

    } 
+0

有什麼比clientvalidation – user207888 2013-02-08 17:37:40

回答

1

它做什麼你告訴它。

的HTML <form>標籤發送POST請求在action屬性的URL。

Html.BeginForm()創建<form>標籤與action屬性指向您的控制器。

當你明確地設置action屬性,更換MVC中的價值,並使其直接進入該網址。

+0

方式ATLEAST驗證頁面之前得到它提交......其他還有什麼比clientvalidation – user207888 2013-02-08 17:39:48

+0

@ user207888方式ATLEAST驗證頁面之前得到它提交...其他:不,你不能執行服務器端代碼,但不會發送到您的服務器。 – SLaks 2013-02-08 19:31:50

0

如果你想發佈到其他網站之前,與你的數據在服務器端的東西,刪除action屬性,這樣你會被張貼到相同的URL在beggining。在處理此表單中的POST的操作中,並執行驗證準備您的數據。準備就緒後,使用POST方法使用WebRequest class將此數據發送到其他網站。

+0

感謝我使用(VAR的客戶=新的Web客戶端())做了 {VAR 值=新的NameValueCollection {{ 「手機」,demoModel.phone},{ 「公司」,demoModel.company},{ 」 lead_source」, 「演示申請」} }; //發送用於處理值的外部URL 變種結果= client.UploadValues( 「HTTPS://測試/後」); – user207888 2013-02-08 20:29:54

+0

@ user207888我很高興你取得了你想要做的。如果我的答案有幫助,但您沒有使用我的解決方案,那麼您可以投我的答案,然後[用您的解決方案發布自己的答案,然後接受它](http://blog.stackoverflow.com/2011/07/its -ok對詢問和回答,你自己的問題/)。 – 2013-02-08 20:42:47