gpt4 book ai didi

asp.net-mvc-5 - 无法从 ASP.NET MVC 5.1 上的 UrlHelper 调用 Action 方法

转载 作者:行者123 更新时间:2023-12-05 01:04:15 31 4
gpt4 key购买 nike

我正在尝试为我的 ASP.NET MVC 5.1 应用程序创建单元测试。

我想使用 UrlHelper.Action() 方法验证传出 URL。
我可以用 ASP.NET MVC 4 做到这一点,但不能用 ASP.NET MVC 5.1。

调用 Action() 方法时出现异常:

System.Web.dll 中发生类型为“System.NotImplementedException”的未处理异常

附加信息:未实现该方法或操作。

请帮我解决!
谢谢

最佳答案

我遇到了同样的问题。就我而言,NotImplementedException来自 HttpContextBase.GetService .

下面的代码解决了这个问题:

public override object GetService(Type serviceType)
{
return DependencyResolver.Current.GetService(serviceType);
}

关于asp.net-mvc-5 - 无法从 ASP.NET MVC 5.1 上的 UrlHelper 调用 Action 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23488489/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com