2014-04-19 468 views
0

我有一個應用程序,如果聯合所有者==是它應該顯示partialview。我Model.cs是從模型返回值到控制器

[Display(Name = "Joint Owner")] 
public string JointOwner { get; set; } 

和我的看法是

<div class="form-group"> 
    @Html.LabelFor(m => m.JointOwner, new { @class = "col-md-3 control-label" }) 
    <div class="col-md-9"> 
     <label>@Html.RadioButtonFor(m => m.JointOwner, new { @class = "form-control", value="Yes"})&nbsp;Yes</label> 
     <label>@Html.RadioButtonFor(m => m.JointOwner, new { @class = "form-control", value = "No" })&nbsp;No</label> 
     @Html.ValidationMessageFor(m => m.JointOwner) 
    </div> 
</div> 

我需要選擇yes的值時,返回partialview。我將如何在模型中處理這個問題?或者會更建議使用JavaScript/jQuery?

public ActionResult PrimaryApplicant(PrimaryApplicantViewModel model) 
{ 
    // Make sure session didn't get eaten. 
    var loanType = ""; 
    if (Session["LoanType"] != null) 
    { 
     loanType = Session["LoanType"].ToString(); 
    } 

    // Here we decide which view to show next. in the frotn end you may need to handle what to change labels to in the wizard maybe via JQ/JS 
    if (loanType == "Auto Refinance") 
    { 
     return PartialView("AutoRefinance"); 
    } 
    else if (loanType == "Auto Purchase") 
    { 
     return PartialView("AutoPurchase"); 
    } 
    else 
    { 
     // You'd want to actually handle it if somehow you got a bad value, I just did it so VS didn't whine. 
     return PartialView("PrimaryApplicantPartial");    
    } 
} 
+0

如果你用javascript來做這個,那肯定會更好。 – mpora

+0

我認爲你有你的術語混合在那裏。而且,如果這是在一個表單內,你將不得不使用jquery。你不能嵌套窗體。加載部分視圖並將其隱藏在頁面加載上可能更容易。 – Jonesopolis

回答

1

這將b更好,如果你,如果你想要一個即時的結果,而不是處理它的後端/模型使用jQuery。如果你不喜歡局部視圖,只需將它設爲隱藏區域,如果聯合主人表示是,就讓它可見。你可以使用jQuery hide and show

0

更優選使用jquery,您可以使用這樣的:

先在視圖中創建的局部視圖容器即

<div class="table-rec-container"></div> 

那麼的document.ready內創建函數()像這樣:

function Partialview() { 

     var chkradio = $('#JointOwner').val(); 

     if(chkradio ==true) 
     { 

     jQuery.ajax({ 
      url: 'url of partial view', 
      type: "GET", 
      success: function (data) { 

       $('.table-rec-container').html(""); 
       $('.table-rec-container').html(data); 
      } 
     }); 
     } 

    } 
相關問題