2017-01-06 1 views
0

ClassA을 모델로 사용하고 view1에는 부분보기가 있습니다 .. 부분 뷰에서 ClassB을 모델로 사용하고 싶습니다.부분 뷰에서 다른 모델 사용

이 가능합니까?

편집classB

public class Device 
    { 

     public int DeviceId { get; set; } 

     public string SerialNo { get; set; } 

     public string IMME { get; set; } 

     public string RefNo { get; set; } 

     public string Supplier { get; set; } 

     public string Brand { get; set; } 

     public string ModelNo { get; set; } 

     public DateTime PurchaseDate { get; set; } 

     public DateTime RegisterDate { get; set; } 

     public string Notes { get; set; } 

     public virtual ICollection<ContractsDevice> ContractsDevices { get; set; } 
    } 

여기에서의 조치 방법 추가

[HttpGet] 
     public ActionResult AssignDevice() 
     { 
      //list of devices 
      List<Device> dev = new List<Device>(); 
      dev.Add(new Device { Brand = "Samsung" }); 
      dev.Add(new Device { Brand = "SONY" }); 

      return PartialView(); 
     } 

여기에 부분보기 : 당신이 실제로보기 위해 필요한 첫째

<div class="modal-header"> 
    <h4 class="modal-title">Assign Device</h4> 
</div> 
<div class="modal-body"> 
    Devices list here 
</div> 
<div class="modal-footer"> 
    <button type="button" class="btn btn-primary">Save</button> 
    <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button> 
</div> 
+0

예 그렇습니다, 당신은 어떻게이 부분을 요구하고있다 : 작업에 데이터를 반환하는 것을 잊지 마세요, 마지막으로

@Html.Action("AssignDevice") 

: 그래서 당신은이 같은 부모 뷰를 형성 호출한다 그래도? – DavidG

+0

@DavidG'@ {Html.RenderPartial ("AssignDevice");}' –

+0

처음에는 구두점이 많이 필요 없습니다.'@Html.RenderPartial ("AssignDevice")'는 충분하고 깨끗합니다. 둘째,'ClassB' 모델이 어디에 있는지 묻는 것을 잊었습니다. – DavidG

답변

1

List<Device> a 엄격히 단지 부분적인하지

@model System.Collections.Generic.List<Device> 

<div class="modal-header"> 
    <h4 class="modal-title">Assign Device</h4> 
</div> 
<div class="modal-body"> 
    @foreach(var device in Model) 
    { 
     <div>@device.SerialNo</div> 
    } 
</div> 
<div class="modal-footer"> 
    <button type="button" class="btn btn-primary">Save</button> 
    <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button> 
</div> 

가 두 번째로 당신이 실제로 자식 작업으로이 전화하는거야 : 단지 Device 그래서보기는 다음과 같이해야하지 ND.

return PartialView(dev); 
+0

감사합니다. 시간 내 주셔서 감사합니다. –

관련 문제