2012-01-19 81 views
1

我在頁面上有2個驗證表單。2驗證組

<div id='LogOn' style="background-color: White;"> 
    @using (Ajax.BeginForm("LogOnAjax", "Home", new AjaxOptions { UpdateTargetId = "LogOn", OnSuccess = "logInComplete" })) 
    { 
     //ITW2012Mobile.ViewModels.LogOnModel m = Model; 
     @Html.HiddenFor(model => model.IsLoggedIn) 
     @Html.HiddenFor(model => model.ReturnUrl) 
     <div> 
      @Html.ValidationSummary() 
     </div> 
     <div> 
      @Html.LabelFor(model => model.UserName) 
      @Html.EditorFor(model => model.UserName) 
     </div> 
     <div> 
      @Html.LabelFor(model => model.Password) 
      @Html.EditorFor(model => model.Password) 
     </div> 
     <div> 
      <input type="submit" value="Login" /> 
     </div> 
    } 
</div> 

<fieldset> 
    @using (Html.BeginForm(Model.ActionMethod, Model.Controller)) 
    { 
     @Html.ValidationSummary() 
..... 
      <div class="display-label"> E-mail Address * </div> 
      <div class="display-field"> 
      @Html.EditorFor(model => model.Username) 
      @Html.ValidationMessageFor(model => model.Username) 
      </div> 
      <div class="display-label"> Create Password * </div> 
      <div class="display-field"> 
      @Html.PasswordFor(model => model.Password) 
      @Html.ValidationMessageFor(model => model.Password) 
      </div> 

     <p> 
      <input type="submit" value="Create" /> 
     </p> 
    } 
</fieldset> 

我如何可以標記ModelState.AddModelError是第一種形式,因爲我看到了同樣的錯誤在validation summary兩個地方呢?

回答

0

我如何可以標記ModelState.AddModelError是第一種形式

你不能的。

你可以做的是有ValidationMessageFor爲每個表單屬性而不是ValidationSummary

+0

但我需要在這兩個地方驗證摘要。存在解決方案嗎? – John

+0

@John。不。抱歉。 **: - (** – gdoron

+0

@John。你可以用你想要的邏輯做你自己定製的'驗證總結''HtmlHelper'。 – gdoron