亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用字符串作為 Id 測試詳細信息操作

使用字符串作為 Id 測試詳細信息操作

C#
人到中年有點甜 2023-07-09 17:06:52
我創建了一個接口和存儲庫,其中包含通過測試的 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>

所以問題是模型的數據在顯示時被忽略了



查看完整回答
反對 回復 2023-07-09
  • 1 回答
  • 0 關注
  • 135 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號