I have a problem that includes presenting all data from a table through a stored procedure. I'm using LINQ to access my stored procedure but the thing is that my result (data shown) is only the last row from my tables. I can't get it to work... would deeply appreciate if someone could help me / explain what im doing wrong.
Model: RecipeModel
public class RecipeModel
{
.....
public void GetAllRecipes()
{
DataClassesDataContext db = new DataClassesDataContext();
var result = db.p_get_all_recipes();
foreach (var r in result)
{
this.recipeName = r.name;
this.recipeDescription = r.description;
this.recipeSteps = r.steps;
this.createdAt = r.createdAt;
this.updatedAt = r.updatedAt;
this.ownerID = r.owner_id;
}
}
Controller: RecipeController
public class RecipeController : Controller
{
[HttpGet]
public ActionResult Index()
{
RecipeModel rec = new RecipeModel();
rec.GetAllRecipes();
return View(rec);
}
View (Razor): Index
@model MVC3_LINQ_SP.Models.RecipeModel
@{
ViewBag.Title = "Index";
}
<legend>Recipe </legend>
<p>@Html.DisplayFor(model => model.rName)</p>