[英]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.