我收到此错误(system.web.mvc.webviewpage< tmodel> .model.get返回null。) [英] I am getting this error (system.web.mvc.webviewpage<tmodel>.model.get returned null.)

查看:195
本文介绍了我收到此错误(system.web.mvc.webviewpage< tmodel> .model.get返回null。)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Home Controller 
public ActionResult Index()
{
    MenuModel ObjMenuModel = new MenuModel();
    ObjMenuModel.MainMenuModel = new List<MainMenu>();
    ObjMenuModel.MainMenuModel = GetMainMenu();
    ObjMenuModel.SubMenuModel = new List<SubMenu>();
    ObjMenuModel.SubMenuModel = GetSubMenu();

    return View(ObjMenuModel);
}

public List<MainMenu> GetMainMenu()
{
    List<MainMenu> ObjMainMenu = new List<MainMenu>();
    ObjMainMenu.Add(new MainMenu { ID = 1, MainMenuItem = "Home", MainMenuURL = "#" });
    ObjMainMenu.Add(new MainMenu { ID = 2, MainMenuItem = "System Setup", MainMenuURL = "#" });
    return ObjMainMenu;
}

public List<SubMenu> GetSubMenu()
{
    List<SubMenu> ObjSubMenu = new List<SubMenu>();
    ObjSubMenu.Add(new SubMenu { MainMenuID = 2, SubMenuItem = "Customer Information", SubMenuURL= "Employer" });
    ObjSubMenu.Add(new SubMenu { MainMenuID = 2, SubMenuItem = "Chart Of Accounts", SubMenuURL = "CompanyProfile" });
    return ObjSubMenu;
}

My Model
namespace Ron_Financial_Management_System.Models
{
    public class MenuModel
    {
        public List<MainMenu> MainMenuModel { get; set; }
        public List<SubMenu> SubMenuModel { get; set; }
    }

    public class MainMenu
    {
        public int ID;
        public string MainMenuItem;
        public string MainMenuURL;
    }

    public class SubMenu
    {
        public int MainMenuID;
        public string SubMenuItem;
        public string SubMenuURL;
    }
}





我的布局视图



My Layout view

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title</title>
    <link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
    <link rel="shortcut icon" type="image/x-icon" href="~/Ron.ico" />
    <script src="~/Scripts/modernizr-2.6.2.js"></script>
    <link href="~/Content/style.css" rel="stylesheet" type="text/css" />

    <script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
    <script src="~/Scripts/jquery-1.12.4.min.js"></script>
    <link href="~/Content/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    @*<script src="@url.Content("~/Scripts/jquery-1.8.3.js")" type="text/javascript"></script>
        <script src="@url.Content("~/Scripts/jquery-ui.min.js")" type="text/javascript"></script>*@
    <script src="../../Scripts/script.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            $("#accordian h3").click(function () {
                $("#accordian ul ul").slideUp();
                if (!$(this).next().is(":visible")) {
                    $(this).next().slideDown();
                }
            });
        });
    </script>
</head>
<body>
    @using System.Web.Optimization
    @model Ron_Financial_Management_System.Models.MenuModel
    @using (Html.BeginForm("_Layout", "Shared"))

    {
        <div id="wrapper">
            <div id="menuTop">
                <table>
                    <tr>
                        <td align="center"><a href="@Url.Action("Logout","Login")">Logged In As:</a> </td>
                        <td align="center"><a href="@Url.Action("Logout","Login")">Last Login:</a></td>
                        <td align="center"><a href="@Url.Action("Logout","Login")">Logout</a> </td>
                    </tr>
                </table>
            </div>

            <div id="menuLogo">
                Logo
            </div>
            <div id="banner">
                <img id="img_logo" alt="Logo" src="@Url.Content("~/Content/Images/RFMS_Brand.png")" />
            </div>
            <div id="columnLeft">
                <div id="accordian">
                    <ul>
                        <li>
                            @{
if(Model.MainMenuModel==null){
                                  <span>no items found</span>
                                }
                                else {

                                foreach (var MenuItem in Model.MainMenuModel)
                                {
                                    var SubMenuItem = Model.SubMenuModel.Where(m => m.MainMenuID == MenuItem.ID);
                                    <h3><a href="@MenuItem.MainMenuURL"> @MenuItem.MainMenuItem </a></h3>
                                    if (SubMenuItem.Count() > 0)
                                    {
                                        <ul>
                                            @foreach (var SubItem in SubMenuItem)
                                            {
                                                <li><a href='@SubItem.SubMenuURL'>@SubItem.SubMenuItem</a></li>
                                            }
                                        </ul>
                                        }
                                    }
                                }
                            }
                    </ul>
                </div>
                <br />
            </div>
            <div id="content"> @RenderBody()</div>
            <div id="menuBottom" aling="center">
                © Copyright @DateTime.Now.Year Ron Technologies Ltd
            </div>
        </div>
    }
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>





My Emplyer view



My Emplyer view

@model Ron_Financial_Management_System.Employer
@*@model Ron_Financial_Management_System.Models.MenuModel*@
@{
    Layout = "~/Views/Shared/_Layout.cshtml";

    }
<h4>Employer</h4>





我是什么尝试过:





What I have tried:

Can someone kindly guide me on what could be the problem?



当我点击下拉菜单检查雇主链接时我得到上述错误,我已经尝试了所有方法但没有成功,请帮助

注意:我正在接受此行在我的布局视图中(


when i click at the drop down menu examle the employer link i get the above error, i have tried all means without success kindly help
Note: i am geting the at this line in my layout view (

foreach (var MenuItem in Model.MainMenuModel)

推荐答案

(文件).ready(function(){
(document).ready(function () {


(#accordian h3)。click(function(){
("#accordian h3").click(function () {


(#accordian ul ul)。slideUp();
if(!
("#accordian ul ul").slideUp(); if (!


这篇关于我收到此错误(system.web.mvc.webviewpage&lt; tmodel&gt; .model.get返回null。)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆