MVC-如何根据在同一视图文本框中输入的值设置复选框的显示名称

MVC-How to set Display name for the checkbox based on value enter in the same view textbox

我正在创建 MVC 应用程序。我有一个模型,该模型具有布尔值和显示名称以及一个文本框。目的是无论何时在文本框中进行一些更改,该名称都应反映在复选框显示名称中。

型号:

[Required(ErrorMessage = "Please Enter Account Number")]
[Display(Name = "Account Number")]
public string AccountNumber{ get; set; }


 [Display(Name = "You approving whatever you entered- Your enter AccountNumber is ")]
 [Range(typeof(bool), "true", "true", ErrorMessage = "Please accept the Terms and Conditions by clicking the check the box!")]
 public bool TermsAndConditions { get; set; }

查看:

   <div class="form-group">
        @Html.LabelFor(model => model.AccountNumber, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.AccountNumber, new { htmlAttributes = new { @class = "form-control" } })           
        </div>
    </div>

    <div class="form-group">
        @@Html.CheckBoxFor(x => x.TermsAndConditions)
        @Html.LabelFor(model => model.TermsAndConditions)
        @Html.ValidationMessageFor(x => x.TermsAndConditions)


    </div>

JS:

 $(function () {
        $("#AccountNumber").keyup(function () {
            var text= $("#AccountNumber").val();
            alert('You type: '+text);
            $("#TermsAndConditions").val(text);
            });
        });

当我 运行 页面时,无论我在帐号中做了什么更改,我都可以打印文本。但我无法将该值分配给复选框显示值。请帮助我。

    $("#TermsAndConditions").html(text);

试试这个对我有用。由于只有输入类型可以使用值。