[Route("getdata")]
public ActionResult GetData()
{
DataSet ds= _getdatabasedata.Igetdatabasedata();
// return Content(ds.Tables[0].Rows[0][0].ToString());
return View(ds.Tables[0]);
}
通過View回傳一個記錄集
在getdata.cshtml中使用
@model WebApplication1.Models.Getdatabasedata
報下面的錯
InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'System.Data.DataTable', but this ViewDataDictionary instance requires a model item of type 'WebApplication1.Models.Getdatabasedata'.
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.EnsureCompatible(object value)
意思是我傳入的東西,與里面的實體不一致。
Getdatabasedata 是一個類。里面有個方法Igetdatabasedata 作用就是從資料庫中回傳記錄集
怎樣才能在getdata.cshtml中把記錄集里的資料取出來呢?
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/238275.html
標籤:ASP.NET
上一篇:用C#+Selenium+ChromeDriver 爬取網頁,完美模擬真實的用戶瀏覽行為
下一篇:c#如何提取物件?
