MVC3 破坏 Linq2Sql
我一直在将网站从 MVC2 转换为 MVC3,虽然我已设法使其正常工作,但我受到错误消息
“传递到字典中的模型项的类型为 'System.Data.Linq.SqlClient.SqlProvider+SingleResult` 1[NutritionLabel3.Models.sp_get_ingredientNutritionFoomasResult]',但此字典需要类型为“NutritionLabel3.Models.sp_get_ingredientNutritionFoomasResult”的模型项。”
此错误来自实现 Linq2Sql 数据层的模型层。这段代码在 MVC2 中运行良好。我通过使用新的 Linq2Sql 接口构建新的 MVC3 站点来进行了许多测试,以验证这是可重复的。控制器中 Linq2Sql 调用的典型实现如下所示:
public ActionResult Index()
{
NutritionLabel3.Models.testDataContext dbContext = new Models.testDataContext();
var nutritionData = dbContext.sp_get_ingredientNutritionFoomas(2, 1, 2);
return View(nutritionData);
}
看来隐式类型转换消息非常神秘。有人在 MVC3 中打过这场仗吗?
任何帮助将不胜感激!
帕特C
I have been converting a site from MVC2 to MVC3 and while I have managed to get it working I am plagued by the error message
"The model item passed into the dictionary is of type 'System.Data.Linq.SqlClient.SqlProvider+SingleResult`1[NutritionLabel3.Models.sp_get_ingredientNutritionFoomasResult]', but this dictionary requires a model item of type 'NutritionLabel3.Models.sp_get_ingredientNutritionFoomasResult'. "
This error comes from the Model layer that implements a Linq2Sql data layer. This code works fine in MVC2. I have conducted a number of tests by building new MVC3 sites with a new Linq2Sql interface to verify that this is repeatable. A typical implementation of a Linq2Sql call in the controller would look like this:
public ActionResult Index()
{
NutritionLabel3.Models.testDataContext dbContext = new Models.testDataContext();
var nutritionData = dbContext.sp_get_ingredientNutritionFoomas(2, 1, 2);
return View(nutritionData);
}
It seems that the implicit type conversion message is very arcane. Has anyone fought this battle yet in MVC3?
Any help would be much appreciated!!
PatC
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
Try: