我有一个问题,包括通过存储过程显示表中的所有数据。我正在使用 LINQ 访问我的存储过程,但问题是我的结果(显示的数据)只是我的表中的最后一行。我无法让它工作......如果有人可以帮助我/解释我做错了什么,我将不胜感激。
模型: 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;
}
}
控制器:RecipeController
public class RecipeController : Controller
{
[HttpGet]
public ActionResult Index()
{
RecipeModel rec = new RecipeModel();
rec.GetAllRecipes();
return View(rec);
}
查看(剃刀):Index
@model MVC3_LINQ_SP.Models.RecipeModel
@{
ViewBag.Title = "Index";
}
<legend>Recipe </legend>
<p>@Html.DisplayFor(model => model.rName)</p>