我希望在布局共享视图上有3个下拉列表(使用我将要创建的模型中的视图包),这将影响所有其他视图上显示的数据。
最好的方法是什么? 过滤下拉列表只需要下拉列表2.下拉列表2将影响所有页面。 DropDown 3只会影响" ScoreCard"之一。
编辑1
我现在有了basemodel模型和控制器,如下所示。
namespace RapidScan_v2.Models
{
public class LayoutBaseModel
{
[Key]
public string ContractID { get; set; }
public string ContractName { get; set; }
public string CountryCode { get; set; }
public string CountryName { get; set; }
public Nullable<System.DateTime> SnapshotMonth { get; set; }
}
}
的Controler:
namespace RapidScan_v2.Controllers
{
public class LayoutBaseModelController : Controller
{
private RapidScanEntities2 db = new RapidScanEntities2();
// GET: LayoutBaseModel
public ActionResult Index()
{
List<LayoutBaseModel> model = new List<LayoutBaseModel>();
var fact_contract_actions_mn = (from a in db.v_contract_detail
join b in db.fact_contract_actions_mn
on a.ContractID equals b.ContractID
select new
{
ContractID = b.ContractID,
ContractName = a.ContractName,
CountryCode = a.CountryCode,
CountryName = a.CountryName,
SnapshotMonth = a.SnapshotMonth
}).ToList();
foreach (var item in fact_contract_actions_mn)
{
model.Add(new LayoutBaseModel()
{
ContractID = item.ContractID,
ContractName = item.ContractName,
CountryCode = item.CountryCode,
CountryName = item.CountryName,
SnapshotMonth = item.SnapshotMonth
});
}
ViewBag.CountryName = new SelectList(db.v_contract_detail, "CountryCode", "CountryName");
ViewBag.ContractID = new SelectList(db.v_contract_detail, "ContractID","ContractName");
ViewBag.SNapshotMonth = new SelectList(db.v_contract_detail, "SnapshotMonth");
return View(model);
}
}
}
添加到&#34; _Layout&#34;视图。 {@model IEnumerable&lt; RapidScan_v2.Models.LayoutBaseModel&GT; }
但是现在出现错误:
&#34;传递到字典中的模型项的类型是&#39; System.Collections.Generic.List 1[RapidScan_v2.Models.ActionsBenefitViews]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1 [RapidScan_v2.Models.LayoutBaseModel]&#39;。&#34;