我有一個應用程序,如果聯合所有者==是它應該顯示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"}) Yes</label>
<label>@Html.RadioButtonFor(m => m.JointOwner, new { @class = "form-control", value = "No" }) 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");
}
}
如果你用javascript來做這個,那肯定會更好。 – mpora
我認爲你有你的術語混合在那裏。而且,如果這是在一個表單內,你將不得不使用jquery。你不能嵌套窗體。加載部分視圖並將其隱藏在頁面加載上可能更容易。 – Jonesopolis