2012-07-09 115 views
0

對話內容ASP.NET MVC3 jQuery的對話框驗證摘要錯誤顯示?

<div id="div_dialog_container" class="dialog_container"> 
@using (Html.BeginForm((string)ViewBag.FormAction, "Musteri")) 
{ 
    <div id="div_iu_form_container" class="ui_form_container"> 
     <div>@Html.ValidationSummary(true, "Müşteri Kaydı Başarısız! Lütfen Bilgileri Kontrol Ediniz.") 
     </div> 
     <table> 
      <thead> 
       <tr> 
        <th colspan="2">Genel Bilgiler</th> 
       </tr> 
      </thead> 
      <tbody> 
       <tr> 
        <td>@Html.LabelFor(x => x.musteri_no):</td> 
        <td>@Html.TextBoxFor(x => x.musteri_no) 
         @Html.ValidationMessageFor(x => x.musteri_no)</td> 
       </tr> 
       <tr> 
        <td>@Html.LabelFor(x => x.musteri_adi):</td> 
        <td>@Html.TextBoxFor(x => x.musteri_adi) 
         @Html.ValidationMessageFor(x => x.musteri_adi)</td> 
       </tr> 
       <tr> 
        <td>@Html.LabelFor(x => x.sektor):</td> 
        <td>@Html.TextBoxFor(x => x.sektor) 
         @Html.ValidationMessageFor(x => x.sektor)</td> 
       </tr> 
      </tbody> 
      <tfoot></tfoot> 
     </table> 

控制器

[HttpPost] 
    public JsonResult JsonMusteriDuzenle(TblMusteriler musteri, string returnUrl) 
    { 
     if (ModelState.IsValid) 
     { 
      try 
      { 
       mus_dbo.update_musteri(musteri); 
       return Json(new { success = true, redirect = returnUrl }); 
      } 
      catch (Exception e) 
      { 
       ModelState.AddModelError("", "Müşteri güncelleme hatası."); 
      } 
     } 

     return Json(new { errors = GetErrorsFromModelState() }); 
    } 

我想顯示錯誤文本框的BUTTOM。但它顯示在頂部是這樣的:

enter image description here

我怎麼能顯示每個錯誤自己的文本框的BUTTOM?

我想這一點:

enter image description here

感謝。

回答

0
<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> 

此線在我的母版,我說在我的部分頁面這些行。然後它按照我的意見工作。

感謝意見。

2

您從控制器動作返回JSON在這兩種情況下。你不能指望出現任何錯誤。你應該返回一個局部視圖包含表單,如果你想的錯誤顯示:

[HttpPost] 
public ActionResult JsonMusteriDuzenle(TblMusteriler musteri, string returnUrl) 
{ 
    if (ModelState.IsValid) 
    { 
     try 
     { 
      mus_dbo.update_musteri(musteri); 
      return Json(new { success = true, redirect = returnUrl }); 
     } 
     catch (Exception e) 
     { 
      ModelState.AddModelError("", "Müşteri güncelleme hatası."); 
     } 
    } 

    return PartialView("_NameOfPartialContainingTheForm", musteri); 
} 

,然後調用這個動作,你必須更換包含您的形式與新的部分的div的內容你的JavaScript代碼中:

success: function(result) { 
    if (result.success) { 
     // the controller action return JSON success 
     alert('Thanks'); 
    } else { 
     // The controller action returned a PartialView 
     // So now you have to refresh the DOM if you want 
     // to see errors showing up 
     $('#id_of_some_div_that_contains_the_partial').html(result); 
    } 
} 

這是假設在你的主視圖你有一個包含分區:

<div id="id_of_some_div_that_contains_the_partial"> 
    @Html.Partial("_NameOfPartialContainingTheForm") 
</div> 
+0

JsonResult和partialView(類型不匹配) – 2012-07-09 09:56:55

+0

回答更新。你的動作簽名必須使用'ActionResult'作爲返回類型。 – 2012-07-09 09:57:26

相關問題