2012-08-07 20 views
0

當我在我的「評論」頁面回發時,我檢查模型狀態並根據結果重新顯示頁面或繼續。我有兩個問題。回傳問題

當驗證失敗時,它在部分視圖上掛起,它在原始get頁面上正確加載。

編輯:這是由[HttpGet]屬性應用於部分視圖的方法引起的。我刪除了屬性和部分重新調整。

如果我註釋掉部分,那麼整個頁面沒有任何CSS樣式,這些都是黑白文字。 編輯:我仍然有樣式從頁面

[HttpGet] 
    public ActionResult Review() 
    { 
     var agmtsService = new AgreementsService(); 
     bool? scoreRelease = agmtsService.GetReleaseScoreIndicator(); 

     var vm = new ReviewModel {ReleaseScoreIndicator = scoreRelease}; 

     return View(vm); 
    } 




    [HttpPost] 
    public ActionResult Review(ReviewModel model) 
    { 

     if(!ModelState.IsValid) 
     { 
      return View(model);`**This is displaying the view w/o head section and no css**` 
     } 

     return RedirectToAction("CheckOut", "Financial"); 
    } 

編輯丟失問題:

視圖模型

公共類ReviewModel {

public bool? ReleaseScoreIndicator { get; set; } 


    // Terms & Conditions 
    [RequiredToBeTrue(ErrorMessage = "Eligibility Checkbox must be checked.")] 
    public bool TermsEligibility { get; set; } 

    [RequiredToBeTrue(ErrorMessage = "True and Accurate Checkbox must be checked.")] 
    public bool TermsAccurate { get; set; } 

    [RequiredToBeTrue(ErrorMessage = "Identity Release Checkbox must be checked.")] 
    public bool TermsIdentityRelease { get; set; } 

    [RequiredToBeTrue(ErrorMessage = "Score Release Checkbox must be checked.")] 
    public bool TermsScoreRelease { get; set; } 

}

公共類RequiredToBeTrueAttribute:RequiredAttribute標籤 { 公共覆蓋BOOL的IsValid(對象值) { 返回值=空& &(布爾)值; }}

查看

@model Registration.Web.Models.ReviewModel 

@{ 
    ViewBag.DisableNavigation = true; 
} 
<script type="text/javascript"> 
    $(document).ready(function() { 
     $('.open_review').toggle(function() { 
      $(this).text('Done').parents('.review_section').addClass('open_for_review').find('.review_content').slideDown('fast'); 
      return false; 
     }, function() { 
      $(this).text('Review').parents('.review_section').removeClass('open_for_review').find('.review_content').slideUp('fast'); 
      return false; 
     }); 


    }); 



</script> 

<div class='section module'> 
      <h2> 
      Please Review Your Application 
      </h2> 
      <p> 
      Remember that your application fee is 
      <strong> 
       not refundable. 
      </strong> 
      Review your information below and make corrections before submitting. 
      </p> 
      <div class='review_section'> 
      <a class="button open_review" href="#">Review</a> 
      <h4> 
       Identification 
      </h4> 
      @{Html.RenderAction("Review", "PersonalInformation");} 
      </div> 
      <div class='review_section'> 
      <a class="button open_review" href="#">Review</a> 
      <h4> 
       Education 
      </h4> 
      @{Html.RenderAction("Review", "MedicalEducation");} /////hangs here   
      </div> 
      <div class='review_section'> 
      <a class="button open_review" href="#">Review</a>        
       @{Html.RenderAction("Review", "PostGraduate");}////then hangs here 
      </div> 
      </div> 
      <div class='actions' id='terms_and_conditions'> 






@using (Html.BeginForm("Review", "Agreements", FormMethod.Post)) 
{ 

    //"reviewForm","Agreements", FormMethod.Post 

    @Html.ValidationSummary(true) 


    <div class='group' id='data_release'> 
     <h4> 
      Data Release 
     </h4> 

     <p> 
      Do you wish to release your scores? 
     </p> 
     <ul class='input_group'> 
      <li> 
       @Html.RadioButtonFor(model => model.ReleaseScoreIndicator, true) 
       <label> 
        Yes 
       </label> 
      </li> 
      <li> 
       @Html.RadioButtonFor(model => model.ReleaseScoreIndicator, false) 
       <label> 
        No 
       </label> 
      </li> 
     </ul> 



    </div> 











       <div class='group' id='terms'> 
        <h4> 
         Terms &amp; Conditions 

        </h4> 
        @Html.ValidationSummary(false) 

       <table> 
       <tbody> 
        <tr> 
         <th> 
          @Html.CheckBoxFor(x => x.TermsEligibility) 
         @* @Html.CheckBox("terms_eligibility")*@ 

         </th> 
        <td> 
         <label for='terms_eligibility'> 
         I currently meet all of the 
         <a href="" target="_blank"> requirements</a> 
         and have read the 
         <a href="" target="_blank">Information</a> 
         </label> 
        </td> 
        </tr> 
        <tr> 
         <th> 
          @Html.CheckBoxFor(x => x.TermsAccurate) 
         @* @Html.CheckBox("terms_accurate")*@ 

         </th> 
        <td> 
         <label for='terms_accurate'> 
         The information I've provided is true and accurate 
         </label> 
        </td> 
        </tr> 
        <tr> 
         <th> 
          @Html.CheckBoxFor(x => x.TermsIdentityRelease) 
         @* @Html.CheckBox("terms_identity_release")*@ 

         </th> 
        <td> 
         <label for='terms_identity_release'> 
         I authorize the release 
         </label> 
        </td> 
        </tr> 
        <tr> 
         <th> 
          @Html.CheckBoxFor(x => x.TermsScoreRelease) 
          @*@Html.CheckBox("terms_score_release")*@ 

         </th> 
        <td> 
         <label for='terms_score_release'> 
         I agree 
         </label> 
        </td> 
        </tr> 
       </tbody> 
       </table> 
      </div> 
       <div class='actions'> 


          <input type="submit" value="Go To Checkout" class="button" /> 




        <a class="button" onclick="getForMasterPage('@Url.Action("CheckOut", "Financial")', null);">BYPASS</a> 
       </div> 

} </div> 
+0

我們可以看到您的視圖和視圖模型嗎? – Pluc 2012-08-07 19:04:54

回答

1

你需要設置被張貼回報ReleaseScoreIndicator?它看起來像是爲最初的GET設置的,但後來的一個,它沒有設置。該視圖是否使用該屬性?

+0

是的,我意外刪除了該代碼。我會將其添加回來,看看會發生什麼 – 2012-08-07 19:05:43

+0

我爲該發佈添加了代碼,它沒有任何區別。我仍然得到相同的結果....它掛在MedEd部分。 – 2012-08-07 19:45:46

+0

Med部分中的哪條線會掛在?這個觀點是什麼樣子的? – Josh 2012-08-07 19:49:23