내가 원하는 것은 두 개의 다른 테이블의 정보로 많은 레이블을 채우는 것입니다. 제출 버튼을 누르면, 내 Post 메소드를 치고 사용자가 입력 한 정보를 저장하고 정보가 자동으로 DB에 채워지지만 Get 메소드에 문제가 있습니다. 내 컨트롤러 내 가져 오기 방법은 다음과 같습니다ViewModel을 사용하여 여러 테이블의 값이있는 페이지로드
[HttpGet]
public ActionResult AddOrganization(int peopleID = 1)
{
var peopleModel = db.People.Include("EmployeeContacts").Single(g => g.PeopleID == peopleID);
return View("../Setup/AddOrganization", peopleModel);
}
을하지만, 나는이 모양이 페이지에 대한 가져 오기 및 포스트 방법을 위해 필요한 모든 테이블을 포함하는 뷰 모델이있어 :
를 :public class AddOrganizationViewModel
{
public MusicStore.Models.Organizations Organizations { get; set; }
public MusicStore.Models.People People { get; set; }
public MusicStore.Models.OrganizationOptions OrganizationsOptions { get; set; }
public MusicStore.Models.EmployeeContacts EmployeeContacts { get; set; }
}
뷰가 처음로드 그래서
, 위의 가져 오기 방법이라고, 나는 여기에
The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.People_8080C33752A42A0C994331F5015BCCFCEB99B3ECD7AB8CA2BB11ABE67851B81B', but this dictionary requires a model item of type 'MusicStore.ViewModels.AddOrganizationViewModel'.
말하는 오류도 내보기입니다 얻을
<h2>AddOrganization</h2>
@model MusicStore.ViewModels.AddOrganizationViewModel
@using (Html.BeginForm("Add", "AddOrganization"))
{
<fieldset>
<legend>CONTACT INFORMATION</legend>
<div class ="editor-label">
@Html.Label("Organization Name")
</div>
<div class ="editor-field">
@Html.TextBoxFor(Model => Model.Organizations.OrgName)
</div>
<div class ="editor-label">
@Html.Label("Phone Number")
</div>
<div class ="editor-field">
@Html.TextBoxFor(Model => Model.Organizations.OrgPhone)
</div>
<div class ="editor-label">
@Html.Label("Point of Contact")
</div>
<div class ="editor-field">
@Html.TextBoxFor(Model => Model.Organizations.OrgPointOfContact)
</div>
<div class ="editor-label">
@Html.Label("Office Location")
</div>
<div class ="editor-field">
@Html.TextBoxFor(Model => Model.Organizations.OrgOfficeLocation)
</div>
</fieldset>
<fieldset>
<legend>FIRST EMPLOYEE OF ORGANIZATION</legend>
<div class ="editor-label">
@Html.Label("Admin First Name")
</div>
<div class ="editor-field">
@Html.TextBoxFor(Model => Model.People.FirstName)
</div>
<div class ="editor-label">
@Html.Label("Admin Last Name")
</div>
<div class ="editor-field">
@Html.TextBoxFor(Model => Model.People.LastName)
</div>
<div class ="editor-label">
@Html.Label("Admin NID")
</div>
<div class ="editor-field">
@Html.TextBoxFor(Model => Model.People.NID)
</div>
<div class ="editor-label">
@Html.Label("Admin SID")
</div>
<div class ="editor-field">
@Html.TextBoxFor(Model => Model.People.SID)
</div>
<div class ="editor-label">
@Html.Label("Admin Email")
</div>
<div class ="editor-field">
@Html.TextBoxFor(Model => Model.EmployeeContacts.Email)
</div>
<div class ="editor-label">
@Html.Label("Admin Phone Number")
</div>
<div class ="editor-field">
@Html.TextBoxFor(Model => Model.EmployeeContacts.PrimaryPhone)
</div>
어떻게 그것이 단지 뷰 모델 유형을 취할 수있는 가져 오기 방법을 통해 뷰에 필요한 정보를 보내려면 어떻게합니까? 이 정보를 내 ViewModel에 추가 할 수있는 방법이 있습니까? 올바른 방향으로 어떤 도움이나 밀림은 좋을 것입니다.
내가 원했던 것과 똑같이 작동했다! 도움 주셔서 대단히 감사합니다! – SantasNotReal