I want to display in my view the results of stored procedure.
Entity Framework automatically imported for me a method that executes a procedure, however I'm not getting the results I expect displaying on the screen.
The imported function is:
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);
}
On ProductsController:
//
// GET: /Products/
public ActionResult Index()
{
ObjectResult<getProductsListForHome_Result> products = db.getProductsListForHome(1, 14);
return View(products.ToList());
}
Using the previous code, when I access http://myapp.com/Products/
I'm getting the following message:
The model item passed into the dictionary is of type 'System.Collections.Generic.List
1[MyApp.Models.getProductsListForHome_Result]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1[MyApp.Models.bm_products]'.
What do I have to do to resolve this?
First, well-written question!
This is a type-casting problem, and it looks like your answer is the accepted answer here:
MVC: The model item passed into the dictionary is of type X, but this dictionary requires a model item of type X
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With