0

ビューモデルを使用してデータを表示しようとしましたが、このようなエラーが発生しました

ディクショナリに渡されたモデル アイテムのタイプは「System.Collections.Generic.List`1[XNet.Repository.Model.FacilityViewModel]」ですが、このディクショナリにはタイプ「XNet.Repository.Model.FacilityViewModel」のモデル アイテムが必要です。

どうすれば問題を解決できますか?? これは私のコード

私のサービス

public List<FacilityViewModel> GetViewHotel(int HotelID)
        {
            List<Hotel> Hotels = (from d in _HotelRepository.All()
                                  where d.HotelID == HotelID
                             select d).ToList();

            List<FacilityViewModel> facilityViewModel = new List<FacilityViewModel>();

            foreach (Hotel hotel in Hotels)
            {
                facilityViewModel.Add(new FacilityViewModel
                {
                    HotelID = HotelID,
                    HotelName = hotel.HotelName,
                    Address1 = hotel.Address1,
                    Address2 = hotel.Address2,
                    HotelDescription = hotel.HotelDescription,
                    HotelInformation = hotel.HotelInformation,
                });
            }

            return facilityViewModel;
        }

私のコントローラー

public ActionResult Index()
        {
            //var x = _hotelService.GetByID(_HotelID);
            List<FacilityViewModel> facilityViewModel = _viewService.GetViewHotel(_HotelID);
            return View(facilityViewModel);
        }

私のビューモデル

public class FacilityViewModel
    {
        public int HotelID { get; set; }
        public string HotelName { get; set; }
        public string Address1 { get; set; }
        public string Address2 { get; set; }
        public string HotelDescription { get; set; }
        public string HotelInformation { get; set; }

    }

私の見解

@model XNet.Repository.Model.FacilityViewModel

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<fieldset>
    <legend></legend>

    <div class="display-label">
         @Html.Label("Hotel ID")
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.HotelID)
    </div>
    <br />

    <div class="display-label">
         @Html.Label("Hotel Name")
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.HotelName)
    </div>
    <br />

    <div class="display-label">
         @Html.Label("Address 1")
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Address1)
    </div>
    <br />

     <div class="display-label">
         @Html.Label("Address 2")
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Address2)
    </div>
    <br />

     <div class="display-label">
         @Html.Label("Hotel Description")
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.HotelDescription)
    </div>
    <br />

     <div class="display-label">
         @Html.Label("Hotel Information")
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.HotelInformation)
    </div>
    <br />
    <br />

</fieldset>

<br />
<input style="width:100px;" type="button" title="EditHotelDetail" value="EditDetails"  onclick="location.href='@Url.Action("Edit", "Hotel", new { HotelID = Model.HotelID})'" />
4

2 に答える 2