Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am creating a small application in MVC3 with Razor. I am using Database first logic by using entity framework (.edmx). I am using stored procedure for every task by using "Add Function Import..."

Now i have a procedure to select a perticuler student record, and this works perfectly but when i want to pass it on corresponding View which is strongly typed with Edit scaffold template then i found following error :

The model item passed into the dictionary is of type 'System.Data.Objects.ObjectResult`1[StudentAlumni.Models.student]', but this dictionary requires a model item of type 'StudentAlumni.Models.student'.

following code is written in my ActionResult Method :
C#
public ActionResult Edit(int id)
       {
           var st = db.proc_SelectAlumniStudent(id);
           if (st == null)
               return RedirectToAction("Index");
           else
               return View(st);
       }

My model is of type: @model StudentAlumni.Models.student


The same problem is also found when i use Delete handler, my question is that how to pass model type values if i use stored procedure and get result in single variable (st in my case) and pass it to View?
Please help me.
Thanks
Posted
Updated 23-Oct-16 19:22pm

1 solution

First you need to change your code like below
C#
var st = db.proc_SelectAlumniStudent(id).ToList();


and then change your return model to IEnumerable
C#
@model IEnumerable<studentalumni.models.student>


Hope this helps
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900