【问题标题】:Pass multiple list from controller to view从控制器传递多个列表以查看
【发布时间】:2020-04-11 21:00:43
【问题描述】:

我有模型的MVC c#应用程序

 public class lstSearchCriteria
{
    public List<lstCampaign> cmpList { get; set; }
    public List<lstAgent> agentList { get; set; }
}
public class lstCampaign
{
    public string campaignName { get; set; }
}
public class lstAgent
{
    public string agentShortName { get; set; }
    public string agentFullName { get; set; }
}

& 返回 lstSearchCriteria 的控制器。我需要在下拉列表中显示 lstCampaign 和 lstAgent。

鉴于我正在做的事情

@using QAApplication.Models
@model QAApplication.Models.lstSearchCriteria

 <select id="lstCampaigns" multiple="multiple">
                                @foreach (var item in Model.cmpList)
                                {
                                    <option >@item.campaignName</option>                                       
                                }
                                </select>
 <div id="divlstAgents">
                            <select id="lstAgents" multiple="multiple">
                                @foreach (var item in Model.agentList)
                                {
                                    <option >@item.agentShortName</option>
                                }
                            </select>
                        </div>

我收到以下错误:传入字典的模型项的类型为“System.Collections.Generic.List`1[QAApplication.Models.lstSearchCriteria]”,但该字典需要一个“QAApplication.模型.lstSearchCriteria'。

从控制器传递多个列表到视图的最佳方式是什么?提前致谢

【问题讨论】:

  • 请添加更多信息,例如编程语言
  • 在控制器中我返回 List。相反,我应该只返回 lstSearchCriteria。解决了。​​

标签: list view model controller send


【解决方案1】:

您正在传递List&lt;lstSearchCriteria&gt;,而视图预期模型仅lstSearchCriteria

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 2016-07-06
    • 1970-01-01
    • 2017-10-12
    相关资源
    最近更新 更多