C# 2个模型1视图查询cshtml
我试图在一个视图中显示来自两个不同表的两个查询的结果。我创建了一个名为ViewModels的文件夹,其中包含一个具有以下内容的类C# 2个模型1视图查询cshtml,c#,sql,C#,Sql,我试图在一个视图中显示来自两个不同表的两个查询的结果。我创建了一个名为ViewModels的文件夹,其中包含一个具有以下内容的类 using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace BillingApp.ViewModels { public class importexport { public IEnumerable<BillingApp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace BillingApp.ViewModels
{
public class importexport
{
public IEnumerable<BillingApp.Models.IMPORT_TRACKER> IMPORT_DATE { get; set; }
public IEnumerable<BillingApp.Models.EXPORT_TRACKER> EXPORT_DATE { get; set; }
}
}
IMPORT_TRACKER和EXPORT_TRACKER是我想要从中提取数据的表。我想从IMPORT_TRACKER中的IMPORT_DATE和EXPORT_TRACKER中的EXPORT_DATE字段中提取数据
我的观点如下
@model IEnumerable<BillingApp.ViewModels.importexport>
@{
ViewBag.Title = "Table Selection";
string connString = "Data Source=SWDB10DSQL;Initial Catalog=BillingUI;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework";
System.Data.SqlClient.SqlConnection db = new System.Data.SqlClient.SqlConnection(connString);
db.Open();
var imp = "select max(IMPORT_DATE) from IMPORT_TRACKER;";
var exp = "select max(EXPORT_DATE) from EXPORT_TRACKER;";
}
@foreach(var item in Model){
@Html.DisplayFor(modelItem => item.IMPORT_DATE(imp))
@Html.DisplayFor(modelItem => item.EXPORT_DATE(exp))
}
我真的不确定我在做什么。它给出了错误,非发票成员“BillingApp.ViewModels.IMPORT_DATE”不能像方法一样使用。和不可开票的成员“BillingApp.ViewModels.EXPORT\u DATE”不能像方法一样使用。只需删除imp和EXP即可在操作中执行此操作,而不在视图中执行