클래스에 일대 다 관계가 있고 뷰에 가상 객체를 표시하려고합니다. 나는 MVC와 EF에 상당히 익숙하다.MVC4 Entity Framework - 일대 다 관계를 표시하는 방법
"요청/작성"작업보기에서 PODObject에 대한 드롭 다운 목록을 표시하려고합니다. 여기
여기public class PODObject
{
public int PODObjectID { set; get; }
public string name { set; get; }
public string CustomAttribute1 { set; get; }
public string CustomAttribute2 { set; get; }
public string CustomAttribute3 { set; get; }
public string CustomAttribute4 { set; get; }
public string CustomAttribute5 { set; get; }
public virtual ICollection<BookingObject> BookingObjectspublic { set; get; }
}
public class RequestsQueueObject
{
// Request Attributes
public int RequestsQueueObjectID { set; get; }
public string CustomAttribute1 { set; get; }
public string CustomAttribute2 { set; get; }
public string CustomAttribute3 { set; get; }
public string CustomAttribute4 { set; get; }
public string CustomAttribute5 { set; get; }
public int PODObjectID { set; get; }
public virtual PODObject PODObject { set; get; }
}
컨트롤러 액션 여기에
public ActionResult Create([Bind(Include="RequestsQueueObjectID,POCPODAccess,CustomAttribute1,CustomAttribute2,CustomAttribute3,CustomAttribute4,CustomAttribute5")] RequestsQueueObject requestsqueueobject)
{
if (ModelState.IsValid)
{
db.RequestsQueueObjects.Add(requestsqueueobject);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(requestsqueueobject);
}
생성됩니다
<div class="form-group">
@Html.DropDownListFor(model => model.PODObject, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PODObject)
@Html.ValidationMessageFor(model => model.PODObject)
</div>
</div>
게시물을 게시하십시오. –