Using Entity Framework 4, MVC3, C#
I have created a complex type within the model of type “SP_Exploder_Result” after clicking Add Function Import.
My controller is as follows:
public ViewResult Exploder(int id)
{
var r = db.SP_PartExploder(id);
return View(id);
}
I try and scaffold the view and iterate over the model passed to it:
@model IEnumerable<EM6.Models.SP_PartExploder_Result>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ComponentId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Total)
</td>
The model item passed into the dictionary is of type ‘System.Int32’, but this dictionary requires a model item of type ‘System.Collections.Generic.IEnumerable`1[EM6.Models.SP_PartExploder_Result]’.
Any ideas how I can convert the model obtained by the Controller to the correct type?
Unless I am misunderstanding your question I think that the the variable “r” needs to be passed into the view rather than the int Id.
At the moment it would appear that the int is being used as the model for the view, rather then the result of your call to db.SP_PartExploder.