我閱讀了一些關於創建包含多個存儲庫的視圖的問題,但似乎無法獲得正確的組合以使其運行。單個視圖中的多個存儲庫
I 3個連接到SQL數據庫中三個不同表的存儲庫。我有正確顯示信息的控制器和視圖模型。我似乎無法獲得部分視圖的工作。當我創建視圖並試圖在視圖中使用partialview時,我收到模型不包含存儲庫的錯誤。我想知道如果我需要只有一個文件與3個存儲庫類中。
我: DomainPlayerRepository.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Domain.Games;
namespace Domain.Abstract
{
public interface DomainPlayerRepository
{
IQueryable<Player> Player { get; }
}
}
DomainGameRepository.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Domain.Games;
namespace Domain.Abstract
{
public interface DomainGameRepository
{
IQueryable<Game> Game { get; }
}
}
GamePartialView.cshtml
@model Domain.Games.Game
<div class="Game">
@Model.Date @Model.NumPlayers @Model.PotMoney
</div>
List.cshtml(對於播放器)
@model IEnumerable<Domain.Games.Player>
@{
ViewBag.Title = "Players";
}
<h2>Player</h2>
@foreach (var p in Model)
{
<div class ="player">
<h3>@p.FName @p.LName Handicap @p.Handicap.ToString()</h3>
</div>
}
@foreach (var p in Model)
{
<div class ="game">
@Html.Partial("GamePartialView", p)
</div>
}
我也一直在試圖讓我的存儲庫在它的視圖模型,但那還沒有工作。
MultiRepositoryViewModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Domain.Games;
namespace WebUI.Models
{
public class MultiRepositoryViewModel
{
public IEnumerable<Player> Player { get; set; }
public IEnumerable<Game> Game { get; set; }
}
}
什麼是你的錯誤的性質?你是什麼意思與「不工作」? – ivowiblo
錯誤在於模型「Domain.Games.Player不包含遊戲」(縮短版本)。哪個更正,我在PartialView中有一個不同的模型,它是「Domain.Games.Game」。我認爲這可能與我在我的控制器中沒有使用摘要有關。不確定究竟是什麼,但我正在嘗試「ActionResult」,而不是「ViewResult」,如果這可能有所幫助。 – coolercargo