我需要在单个视图中显示多个表。这似乎是一个问题,因为该视图只允许从我可以告诉的一个模型定义。我尝试过实施一种解决方法,但一直没有成功。 具体而言,我收到错误消息:“传入字典的模型项类型为'System.Data.Entity.DbSet 1[BillingApp.Models.HEADER_RECORD]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1 [BillingApp.Models.tbl1join]'。”在同一视图中调用多个SQL语句表
观
@model IEnumerable<BillingApp.Models.tbl1join>
@{
ViewBag.Title = "TABLE 01 DISPLAY";
Layout = "../Shared/Layout2.cshtml";
}
@section featured2 {
<html>
<body>
~excluding tables because there are too many fields~
</body></html>
}
类接合两个表(tbl1join.cs)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace BillingApp.Models
{
public class tbl1join
{
public HEADER_RECORD HeaderRecord { get; set; }
public HEADER_EXTENSION_RECORD ExtensionRecord { get; set; }
}
}
模型说明:
HEADER_RECORD.cs
namespace BillingApp.Models
{
using System;
using System.Collections.Generic;
public partial class HEADER_RECORD
{
public int HRID { get; set; }
public string TABLE_NUMBER { get; set; }
public string COMPANY { get; set; }
public string STATE_CODE { get; set; }
public string BILL_CODE { get; set; }
public string RECORD_TYPE { get; set; }
public string MASK_EXTENSION_ID { get; set; }
public string OVERPAYMENT_LIMIT { get; set; }
public string UNDERPAYMENT_LIMIT { get; set; }
public string REFUND_ACTION_OVR { get; set; }
public string REFUND_ACTION_PAR { get; set; }
public string REFUND_ACTION_RTN_PRM { get; set; }
public string REFUND_ACTION_CNC { get; set; }
public string EFT_PAC_OPTION { get; set; }
public string EFT_PAC_NOTICE { get; set; }
public string EFT_PAC_NSF_LIMIT { get; set; }
public string PREMIUM_ROUNDING { get; set; }
public string DB_CC_OPTION { get; set; }
public string NSF_CHECK_LIMIT { get; set; }
public string NSF_CHECK_OPTION { get; set; }
public string FIRST_TERM_BILLING { get; set; }
public string CARRY_DATE_OPTION { get; set; }
public string ENDORSEMENT_DAYS { get; set; }
public string DATE_METHOD { get; set; }
public string RENEWAL_OPTION { get; set; }
public string DROP_DAYS { get; set; }
public string MULTI_PAY_IND { get; set; }
public string MINIMUM_INSTALLMENT { get; set; }
public string ENDORSEMENT_ACTION { get; set; }
public string I_OR_S_OPTION_DAYS { get; set; }
public string S_OPTION_PERCENT { get; set; }
public string SERVICE_CHARGE_PREPAID { get; set; }
public string REINSTATE_OPTION { get; set; }
public string CASH_WITH_APPLICATION { get; set; }
public string DB_CC_NOTICE { get; set; }
public string DOWN_PAY_DAYS { get; set; }
public string MONTH_BY_TERM { get; set; }
public string LEAD_MONTHS { get; set; }
public string INITIAL_MONTHS { get; set; }
public string DB_CC_REJECTS { get; set; }
public string RETURN_ENDORSEMENT_OPTION { get; set; }
public string RETURN_SPLIT_OPTION_PERCENT { get; set; }
public string AUTOMATED_REFUND_DAYS { get; set; }
public string RENEWAL_OPTION_BILL_PLAN { get; set; }
public string EFFECTIVE_DATE { get; set; }
public string MISC_DATA { get; set; }
public string MISC_DATA2 { get; set; }
}
}
HEADER_EXTENSIO N_RECORD.cs
namespace BillingApp.Models
{
using System;
using System.Collections.Generic;
public partial class HEADER_EXTENSION_RECORD
{
public int ERID { get; set; }
public string ETABLE_NUMBER { get; set; }
public string ECOMPANY { get; set; }
public string ESTATE_CODE { get; set; }
public string EBILL_CODE { get; set; }
public string ERECORD_TYPE { get; set; }
public string EMASK_EXTENSION_ID { get; set; }
public string OVERPAYMENT_TOLERANCE_PERCENT { get; set; }
public string UNDERPAYMENT_TOLERANCE_PERCENT { get; set; }
}
}
的控制器(BillingController.cs)
public ActionResult HeaderExtensionRecord()
{
{
return View(db.HEADER_EXTENSION_RECORD);
}
}
public ActionResult HeaderRecordTable1()
{
{
return View(db.HEADER_RECORD);
}
}
更新:
新增tbl1join作为控制器的返回类型,但给一个错误,说这是一个类型被用作变量。
public ActionResult HeaderRecordTable1()
{
{
return View(IEnumerable<tbl1join>);
}
}
你有你的观点接受'IEnumerable'。它看起来像你已经设置好了,为什么你没有控制器操作返回'IEnumerable '? –
Jonesopolis
2014-10-01 19:49:45
这两个模型之间有关系吗?你不能使用导航属性/关系来加入数据吗? – mheptinstall 2014-10-01 20:00:05
你需要以某种方式填充你的模型,即创建'tbl1join's基于你的数据库,但是你需要加入他们 – Jonesopolis 2014-10-01 20:01:42