在MVC视图中显示存储过程的结果(EF 5/MVC 4)

Gui*_*nge 5 c# mysql stored-procedures entity-framework entity-framework-5

目标

我想在我的视图中显示存储过程的结果.

问题

实体框架为我自动导入了一个执行程序的方法,但是我没有得到我期望在屏幕上显示的结果.

导入的功能是:

public virtual ObjectResult<getProductsListForHome_Result> getProductsListForHome(Nullable<int> inOffer, Nullable<int> categoryId)
{
    var inOfferParameter = inOffer.HasValue ?
        new ObjectParameter("inOffer", inOffer) :
        new ObjectParameter("inOffer", typeof(int));

    var categoryIdParameter = categoryId.HasValue ?
        new ObjectParameter("categoryId", categoryId) :
        new ObjectParameter("categoryId", typeof(int));

    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<getProductsListForHome_Result>("getProductsListForHome", inOfferParameter, categoryIdParameter);
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试过了什么

在ProductsController上:

//
// GET: /Products/
public ActionResult Index()
{
    ObjectResult<getProductsListForHome_Result> products = db.getProductsListForHome(1, 14);
    return View(products.ToList());
}
Run Code Online (Sandbox Code Playgroud)

使用前面的代码,当我访问时,http://myapp.com/Products/我收到以下消息:

传递到字典中的模型项的类型为'System.Collections.Generic.List 1[MyApp.Models.getProductsListForHome_Result]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1 [MyApp.Models.bm_products]'.

我该怎么做才能解决这个问题?

Dav*_*sky 3

首先,问题写得好!

这是一个类型转换问题,看起来您的答案是这里接受的答案:

MVC:传入字典的模型项是X类型,但是这个字典需要X类型的模型项