번호 표시 대신 외래 키 값을 표시 할 수있는 방법이 필요합니다.외래 키 기본 키와 연결된 번호 만 표시
@model IEnumerable<Games.Models.tblReview>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
ReviewID
</th>
<th>
Recomendation
</th>
<th>
AvoidOrBuy
</th>
<th>
Score
</th>
<th>
GameIDFK
</th>
<th>
UserName
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ReviewID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Recomendation)
</td>
<td>
@Html.DisplayFor(modelItem => item.AvoidOrBuy)
</td>
<td>
@Html.DisplayFor(modelItem => item.Score)
</td>
<td>
@Html.DisplayFor(modelItem => item.GameIDFK)
</td>
<td>
@Html.DisplayFor(modelItem => item.UserName)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { id=item.ReviewID }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</table>
나는 GameIDFK이 정보가 여기에 표시됩니다 기본적인 보여주기보다는 다수의 내 컨트롤러를 게임의 이름을 표시하는 방법을 원하는 예를 들어 나는 모든 검토를 표시하려면 다음 뷰를 가지고 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Games.Models;
namespace Games.Controllers
{
public class ShowAllReviewsController : Controller
{
//
// GET: /ShowAllReviews/
public ActionResult Index()
{
using (var db = new gamezoneDBEntities())
{
return View(db.tblReviews.ToList());
}
}
//
// GET: /ShowAllReviews/Details/5
public ActionResult Details(int id)
{
return View();
}
//
// GET: /ShowAllReviews/Create
public ActionResult Create()
{
return View();
}
//
// POST: /ShowAllReviews/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /ShowAllReviews/Edit/5
public ActionResult Edit(int id)
{
return View();
}
//
// POST: /ShowAllReviews/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /ShowAllReviews/Delete/5
public ActionResult Delete(int id)
{
return View();
}
//
// POST: /ShowAllReviews/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
는이 사이트가 새로운 오는 게이머에 사용되는 것입니다 나는 게임이 좋은 플레이를 어떻게하는 약관을 원하는대로 게임 외래 키를 얻을 수있는 방법은 리뷰에서 사용자의 클릭을 원하는 그나마 거기 숫자와 게임 이름이없는 것을 볼 수 있습니다.
당신이 도와 주실 수
편집 :
내가 사용하는 다음 내보기 :The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
편집 :하지만 crashses 다음과 같은 오류를 제공
@Html.DisplayFor(modelItem => item.tblGame.GameName)
2 :
namespace Games.Models
{
using System;
using System.Collections.Generic;
public partial class tblReview
{
public int ReviewID { get; set; }
public string Recomendation { get; set; }
public string AvoidOrBuy { get; set; }
public string Score { get; set; }
public int GameIDFK { get; set; }
public string UserName { get; set; }
public virtual tblGame tblGame { get; set; }
}
더 높은 수용률 %를 사용하면 도움을 얻을 수 있습니다. 또한 tblReview 모델의 코드를 게시 할 수 있습니까 – glosrob
Ok는 모델을 게시합니다 – user1137472
http://stackoverflow.com/questions/5360372/the-objectcontext-instance-has-been-disposed-and-can-no-longer- be used for-opera –