2014-04-19 613 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); 
      } 
     }); 
     } 

    } 
相关问题