[英]How to keep radio buttons populated after postback
我有一個頁面,其中包含基於單選按鈕選擇顯示和隱藏的動態行。 還有驗證確保每個字段(顯示)都已填充並具有有效值。 當用戶提交頁面時,它會驗證字段並回發,當文本框值被存儲時,所有單選按鈕都被取消選擇,動態行全部被隱藏。 我想知道如何在回發后保持對單選按鈕和可見/隱藏字段的選擇。
<div class="form-group">
<label asp-for="HaveYouEnteredTheProperty">Have you entered the property?</label>
<div asp-for="HaveYouEnteredTheProperty" class="btn-group btn-group-toggle" data-toggle="buttons" style="width:100%">
<label style="width:50%" class="btn btn-success">
<input type="radio" name="VisitDetailsRadio" id="propYes" value="Yes"/> Yes
</label>
<label style="width:50%" class="btn btn-danger">
<input type="radio" name="VisitDetailsRadio" id="propNo" value="No" /> No
</label>
</div>
<span asp-validation-for="HaveYouEnteredTheProperty" class="text-danger"></span>
</div>
這是我在 cshtml 頁面上的單選按鈕之一
$("input[name=VisitDetailsRadio]").change(function () {
if ($(this).val() == "No") {
$(".VisitDetailsExpandedYes").hide();
$(".VisitDetailsExpandedNo").show();
$(".EnteredProperty").hide();
}
else {
$(".VisitDetailsExpandedYes").show();
$(".VisitDetailsExpandedNo").hide();
$(".EnteredProperty").show();
}
});
這是基於單選按鈕選擇顯示和隱藏字段的 jquery
if (results.IsValid)
{
_context.Results.Add(model);
_context.SaveChanges();
ModelState.Clear();
return View();
}
else
{
results.AddToModelState(ModelState, null);
return View(model);
}
這是在表單末尾按下提交按鈕后的驗證。
任何幫助,將不勝感激。
在高層次上,您需要做的是以下事情:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.