我有一个 ASP.NET MVC 项目,我已经快两个月没有工作了。只要我不更改任何代码,在浏览器中调试就可以正常工作。当我修改任何代码,甚至添加空格时,我都会收到此错误:
An exception of type 'System.NotSupportedException' occurred in EntityFramework.dll but was not handled in user code
Additional information: The type 'System.Web.Routing.RouteCollection+IgnoreRouteInternal' and the type 'System.Web.Mvc.RouteCollectionExtensions+IgnoreRouteInternal' both have the same simple name of 'IgnoreRouteInternal' and so cannot be used in the same model. All types in a given model must have unique simple names. Use 'NotMappedAttribute' or call Ignore in the Code First fluent API to explicitly exclude a property or type from the model.
异常发生在这一行:
var item = Cards.FirstOrDefault(s => s.name == cardName);
我唯一能想到的是,更改路由设置可能是我再次选择该项目之前所做的最后一件事之一,据我所知,那里一切正常。另一件事是我正在使用 TortiseGit 和 bitbucket,但我不知道这会产生什么效果。我还有另一个具有类似设置的项目,没有任何问题。
如果我犯了一个错误,这是我的 RouteConfig.cs
using System;
using System.Web.Mvc;
using System.Web.Routing;
namespace houseOfCards
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Hello",
url: "{controller}/{action}/{name}/{id}"
);
}
}
}
我不知道如何解决这个问题,任何建议将不胜感激。
我遇到了类似的问题,经过三天的调查和调试我设法修复了它,错误消息往往有点误导,因为它只指的是System.Web.Routing.RouteCollection
和System.Web.Mvc.RouteCollectionExtensions
类,这导致人们认为路线与它有关,但事实并非如此,至少就我而言。
就我而言,我错误地将实体的导航属性声明为ICollection<Controller>
,因此实体框架对我想要注册的类感到困惑。
因此,我建议在您的模型中搜索任何名为保留字的属性或类,或者不属于该模型的类,然后将其重命名。
我希望它有帮助
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)