我創建了一個接口和存儲庫,其中包含通過測試的 GetOne(string id) 方法。我的問題是當我運行應用程序并導航到詳細信息鏈接時,頁面顯示為空白。我到處搜索但找不到任何解決方案。// The Repopublic class PostcodesRepository : IPostcodesRepository{? ? private readonly sample6Context _context;? ? public PostcodesRepository(sample6Context context)? ? {? ? ? ? _context = context;? ? }? ? public Task<List<Postcode>> GetAll() =>? ? ? ? _context.Postcode.Include(p => p.DataZoneNavigation).AsNoTracking().OrderByDescending(a => a.Postcode1).ToListAsync();? ? public Task<Postcode> GetOne(string id) =>? ? ? ? _context.Postcode.Include(p => p.DataZoneNavigation).AsNoTracking().FirstOrDefaultAsync(m => m.Postcode1 == id);? ? ? ??? ? }}// Modelpublic? class Postcode{? ? [key]? ? public string Postcode1 { get; set; }? ? public string DataZone { get; set; }? ? public virtual Data DataZoneNavigation { get; set; }}// The Interfacepublic interface IPostcodesRepository{? ? Task<List<Postcode>> GetAll();? ? Task<Postcode> GetOne(string id);}// The Controllerpublic class PostcodesController : Controller{? ? private readonly IPostcodesRepository _postcodesRepository;? ? public PostcodesController(IPostcodesRepository postcodesRepository)? ? {? ? ? ? _postcodesRepository = postcodesRepository;? ? }? ? // GET: Postcodes? ? public async Task<IActionResult> Index()? ? {? ? ? ? return View(await _postcodesRepository.GetAll());? ? }? ? // GET: Postcodes/Details/5? ? public async Task<IActionResult> Details(string id)? ? {? ? ? ? if (id == null)? ? ? ? {? ? ? ? ? ? return NotFound();? ? ? ? }? ? ? ? var postcode = await _postcodesRepository.GetOne(id);? ? ? ? if (postcode == null)? ? ? ? {? ? ? ? ? ? return NotFound();? ? ? ? }? ? ? ? return View(postcode);? ? }}我希望詳細方法能夠正常運行并顯示信息。
1 回答

嚕嚕噠
TA貢獻1784條經驗 獲得超7個贊
在詳細信息視圖標記中,您不顯示數據。您僅顯示顯示名稱。
<div>
<h4>Postcode</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Postcode1)
</dt>
<dd class="col-sm-2">
@Model.Postcode1
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.DataZone)
</dt>
<dd class="col-sm-2">
@Model.DataZone
</dd>
</dl>
</div>
所以問題是模型的數據在顯示時被忽略了
- 1 回答
- 0 關注
- 135 瀏覽
添加回答
舉報
0/150
提交
取消