Partial View Rending Error 传入字典的模型项属于类型

Partial View Rending Error the model item passed into the dictionary is of type

所以我只开发了一个简单的部分视图,它将处理在页面顶部显示消息。

然后我想在我的所有页面中使用该部分视图来处理信息、警告或错误消息。

我创建了一个登录页面,这是我第一次尝试这样做。

它给我一个错误,说明我没有传递正确的类型。我不明白为什么它说我试图传入的字典类型是 Music.Accounts.ViewModels.Log 当它非常清楚地显示时我开发了一个变量,将父模型中的 属性 分配给该变量然后尝试将其作为我的模型传递给我的局部视图。

任何帮助将不胜感激:)

错误和代码如下

谢谢:)

呈现页面时出现系统错误

Additional information: The model item passed into the dictionary is of type
'Music.Accounts.ViewModels.LogOn', but this dictionary requires a model item of type 'System.Collections.Generic.List`1

Class

namespace MMLibrary.MMWeb.MessageHandling
{
    public enum MessageTypes
    {
        TopSummary = 1
        , BottomSummary = 2
        , Error = 3
        , Warning = 4
        , Informational = 5
    }
    public struct Message
    {
        public string PropertyName;
        public string MessageText;
        public MessageTypes MessageType;
    }
}

部分视图渲染

@using MMLibrary.MMWeb.MessageHandling
@model List<Message>

父视图渲染

@using Music.Accounts.ViewModels
@using MMLibrary.MMWeb.MessageHandling
@model LogOn
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    var DisplayMessages = Model.DisplayMessages;
}
@Html.Partial("~/Views/Shared/MessageDisplay.cshtml", DisplayMessages)

父视图的ViewModel

namespace Music.Accounts.ViewModels
{
    public class LogOn
    {
        public string Email { get; set; }
        public string Password { get; set; }
        public bool RememberMe { get; set; }
        public List<Message> DisplayMessages { get; set; }
    }
}

Html.Partial()的第二个参数不能为null,否则会传Model为参数。 在您调用 @Html.Partial("~/Views/Shared/MessageDisplay.cshtml", DisplayMessages) 的那一刻,DisplayMessages 变量为 null,并且模型 (LogOn) 被传递给局部视图。