0
我將以下路由添加到路由集合,然後呼叫返回RedirectToAction("Index", "Company");
停止工作。添加新路由時,RedirectToAction停止工作
routes.MapRoute(
name: "CompanyRoute",
url: "{id}",
defaults: new { controller = "Company", action = "Get" },
constraints: new { id = @"^[a-z]+$" }
);
並出現此錯誤。
Error message: The model item passed into the dictionary is of type
'System.Collections.Generic.List`1[Project.Models.Company]', but
this dictionary requires a model item of type 'Project.Models.Company'.
任何人都知道這個錯誤可能是什麼?
當我刪除路由時,對RedirectToAction的調用工作,所以它必須是路由。 – MikeAlike234
也許另一個行動正在響應給定的路線。儘管如此,除了這點之外,這還是一種。我告訴你錯誤的含義。找出爲什麼你的觀點被通過一個'名單'而不是'公司',錯誤將消失。 –
是的路由(CompanyRoute)接到了呼叫,但你能向我解釋爲什麼?,因爲如果我在地址字段中寫公司/索引,然後默認路由處理它。出於某種原因,調用RedirectToAction(「Index」,「Company」);不會轉換爲公司/索引,因此路線將重定向到Company/Get,其id設置爲null。這是什麼原因造成的? – MikeAlike234