Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 类型为';的未处理异常;具有自定义帮助程序类的System.StackOverflowException_Asp.net Mvc 3 - Fatal编程技术网

Asp.net mvc 3 类型为';的未处理异常;具有自定义帮助程序类的System.StackOverflowException

Asp.net mvc 3 类型为';的未处理异常;具有自定义帮助程序类的System.StackOverflowException,asp.net-mvc-3,Asp.net Mvc 3,我有一个html助手感谢达林,但我已经做了一些事情,使它停止工作 public static MvcHtmlString ValidationStyledMessageFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> ex) { var result = htmlHelper

我有一个html助手感谢达林,但我已经做了一些事情,使它停止工作

 public static MvcHtmlString ValidationStyledMessageFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> ex)
    {

            var result = htmlHelper.ValidationStyledMessageFor(ex);
            var res = string.Format("<span class=\"error required\"><p>{0}<a class=\"close\" href=\"javascript:closeError();\"></a></p></span>", result.ToHtmlString());
            return MvcHtmlString.Create(res);

    }
然而,当它运行时,我得到了一个错误

MyMVC.DLL中发生“System.StackOverflowException”类型的未处理异常

错误正在返回

无法计算表达式,因为当前线程处于堆栈溢出状态

这对我来说毫无意义,有没有什么方法可以调试它,这样我就可以知道发生了什么?

这里:

var result = htmlHelper.ValidationStyledMessageFor(ex);
您正在再次调用自定义助手,该助手调用:

var result = htmlHelper.ValidationStyledMessageFor(ex);
var result = htmlHelper.ValidationStyledMessageFor(ex);
再次调用您的自定义帮助程序,它调用:

var result = htmlHelper.ValidationStyledMessageFor(ex);
var result = htmlHelper.ValidationStyledMessageFor(ex);
。。。依此类推,直到堆栈用完并抛出异常为止

因此,您可能希望调用默认帮助程序,而不是调用自己:

public static MvcHtmlString ValidationStyledMessageFor<TModel, TProperty>(
    this HtmlHelper<TModel> htmlHelper, 
    Expression<Func<TModel, TProperty>> ex
)
{
    var result = htmlHelper.ValidationMessageFor(ex);
    var res = string.Format("<span class=\"error required\"><p>{0}<a class=\"close\" href=\"javascript:closeError();\"></a></p></span>", result.ToHtmlString());
    return MvcHtmlString.Create(res);
}
public static MvcHtmlString ValidationStyledMessageFor(
这个HtmlHelper HtmlHelper,
表达式ex
)
{
var result=htmlHelper.ValidationMessageFor(ex);
var res=string.Format(“{0}

”,result.ToHtmlString()); 返回MvcHtmlString.Create(res); }
在我看来就像一个无限循环或递归。对
ValidationStyledMessageFor
的调用是递归的吗?你的右翼达林,我在做一个大的代码清理,错误地替换了var结果