为什么我有 'System.StackOverflowException' 类型的异常被抛出。在我自己的 htmlhelper 中?

Why I've got Exception of type 'System.StackOverflowException' was thrown. in my own htmlhelper?

我在asp.netmvc中为checkbox写了htmlhelper但是当我想使用it.It时显示异常。System.WhosebugException' was thrown如何解决it.and我也如何将复选框值提交给 htmlhelper 事实上,我想将值复选框提交给我的 htmlhelper。

 public static class HelperUI
    {
        public static MvcHtmlString CheckBoxSimple(this HtmlHelper htmlHelper, bool IsCheck, string name, object htmlAttributes)
        {
            string checkBoxWithHidden = htmlHelper.CheckBoxSimple(IsCheck, name, htmlAttributes).ToHtmlString();
            string pureCheckBox = checkBoxWithHidden.Substring(0, checkBoxWithHidden.IndexOf("<input", 1));
            return new MvcHtmlString(pureCheckBox);
        }
    }




<div class="col-md-6">
    <div class="form-group row">
        status
        <div class="col-md-9">
            @Html.CheckBoxSimple(true, "Status", new { @class = "form-control", placeholder = "status" })

        </div>
    </div>
</div>

WhosebugException往往是死循环或无限递归造成的

在您的情况下,CheckBoxSimple 无限期地调用自身:第一行调用 CheckBoxSimple 而不是 CheckBox