none
MVC5 前台读取后台方法中的二维数值 RRS feed

  • 问题

  • 我在MVC5 中models有一方法,其返回一个二维数据:

    namespace suwenhua.Models.LaoHuangLi

    {

    public class LaoHuangLi:LaoHuangLiShiXianFangFa
        {

     string[,] JiaZiJiRi = new string[,]{
                  {"2017","1","28","鸡","丁酉","太岁康杰","一白","正月","小","壬寅","八白","震卦","胃宿","初一","乙卯","七赤","满","女宿","立春","子时","2","3","23","35","雨水","戊时","2","18","19","32"},
                  {"2017","2","26","鸡","丁酉","太岁康杰","一白","二月","大","癸卯","七赤","巽卦","卯宿","初一","甲申","九紫","破","虚宿","惊蛰","酉时","3","5","15","34","春分","酉时","3","20","18","29"},
                  {"2017","3","28","鸡","丁酉","太岁康杰","一白","三月","小","甲辰","六白","坎卦","毕宿","初一","甲寅","三碧","闭","室宿","清明","亥时","4","4","22","18","谷雨","卯时","4","20","5","18"}}//数据太多,粘贴部分为例

     public string[,] laohuangli_dangri()
            {

    LaoHuangLi A=new LaoHuangLi();

               string[,] dangyue=A.JiaZiJiRi;
                return dangyue;

            }

        }

    }

    数据封装model中如下:

    namespace suwenhua.Models
    {
        public class LaoHuangLi_Models
        {
            public string YangLiNian{get;set;}
            public string YangLiYue{get;set;}
            public string YangLiRi{get;set;}
            public string NongLiShuXiang{get;set;}
            public string NongLiNianJiaZi{get;set;}
            public string NongLiNianTaiSui{get;set;}
            public string NongLiNianJiuXin{get;set;}
            public string NongLiYueFen{get;set;}
            public string NongLiYueDaXiao{get;set;}
            public string NongLiYueJiaZi{get;set;}
            public string NongLiYueJiuXin{get;set;}
            public string NongLiYueBaGua{get;set;}
            public string NongLiYueErShiBaXiu{get;set;}
            public string NongLiRi{get;set;}
            public string NongLiRiJiazi{get;set;}
            public string NongLiRiJiuXin{get;set;}
            public string NongLiRiJianChuShiErZhi{get;set;}
            public string NongLiRiErShiBaXiu{get;set;}
            public string NongLiErShiSiJieQi{get;set;}
            public string NongLiErShiSiJieQi_ShiChen{get;set;}
            public string NongLiErShiSiJieQi_YangLiYue{get;set;}
            public string NongLiErShiSiJieQi_YangLiRi{get;set;}
            public string NongLiErShiSiJieQi_Shi{get;set;}
            public string NongLiErShiSiJieQi_Fen{get;set;}
            public string NongLiErShiSiJieQi_1{get;set;}
            public string NongLiErShiSiJieQi_ShiChen_1{get;set;}
            public string NongLiErShiSiJieQi_YangLiYue_1{get;set;}
            public string NongLiErShiSiJieQi_YangLiRi_1{get;set;}
            public string NongLiErShiSiJieQi_Shi_1{get;set;}
            public string NongLiErShiSiJieQi_Fen_1{get;set;}
        }
    }

    我想把这个数据dangyue在前台View中呈现,该如何写,前台,控件中的代码该怎么写。尽可能写详细一点谢谢;


    2018年6月17日 7:51

答案

  • 后台  controller

     [RoutePrefix("Purchasing/PurchaseOrder"), Route("{action=index}")]    
        public class PurchaseOrderController : Controller
        {
            public ActionResult Index()
            {

                 LaoHuangLi_Models  model=new ..

                 model.YangLiNian="ABC"; 

                 .....

                 return View("~/Modules/Purchasing/PurchaseOrder/PurchaseOrderIndex.cshtml",model);
            }
        }

    前台页面cshtml

    @model  suwenhua.Models.LaoHuangLi_Models
    @{
        ViewData["Title"] = "Dashboard";
        ViewData["PageId"] = "Dashboard";
    }

    <div class="row">
               <h4>@Model.YangLiNian</h4>    这个地方就会显示值ABC
         </div>
                    
                      



      


    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms


    • 已编辑 Shuanghua Li 2018年6月19日 0:35
    • 已标记为答案 外来人 2018年12月20日 13:10
    • 取消答案标记 外来人 2018年12月20日 13:10
    • 已标记为答案 外来人 2018年12月20日 13:10
    2018年6月19日 0:32

全部回复

  • 后台  controller

     [RoutePrefix("Purchasing/PurchaseOrder"), Route("{action=index}")]    
        public class PurchaseOrderController : Controller
        {
            public ActionResult Index()
            {

                 LaoHuangLi_Models  model=new ..

                 model.YangLiNian="ABC"; 

                 .....

                 return View("~/Modules/Purchasing/PurchaseOrder/PurchaseOrderIndex.cshtml",model);
            }
        }

    前台页面cshtml

    @model  suwenhua.Models.LaoHuangLi_Models
    @{
        ViewData["Title"] = "Dashboard";
        ViewData["PageId"] = "Dashboard";
    }

    <div class="row">
               <h4>@Model.YangLiNian</h4>    这个地方就会显示值ABC
         </div>
                    
                      



      


    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms


    • 已编辑 Shuanghua Li 2018年6月19日 0:35
    • 已标记为答案 外来人 2018年12月20日 13:10
    • 取消答案标记 外来人 2018年12月20日 13:10
    • 已标记为答案 外来人 2018年12月20日 13:10
    2018年6月19日 0:32
  • 谢谢了

    2018年12月20日 13:09
  • 问题已经解决,谢谢

    2018年12月20日 13:09
  • 我在MVC5 中有一方法,有一个二维数组,现在我要把二维数组赋值给model,我要怎么做,当我要根据需要返回返回二维数组中的某一行时,我怎么通过model实现。二维数组如下:

    namespace suwenhua.Models.LaoHuangLi

    {

    public class LaoHuangLi:LaoHuangLiShiXianFangFa
        {

     string[,] JiaZiJiRi = new string[,]{
                  {"2017","1","28","鸡","丁酉","太岁康杰","一白","正月","小","壬寅","八白","震卦","胃宿","初一","乙卯","七赤","满","女宿","立春","子时","2","3","23","35","雨水","戊时","2","18","19","32"},
                  {"2017","2","26","鸡","丁酉","太岁康杰","一白","二月","大","癸卯","七赤","巽卦","卯宿","初一","甲申","九紫","破","虚宿","惊蛰","酉时","3","5","15","34","春分","酉时","3","20","18","29"},
                  {"2017","3","28","鸡","丁酉","太岁康杰","一白","三月","小","甲辰","六白","坎卦","毕宿","初一","甲寅","三碧","闭","室宿","清明","亥时","4","4","22","18","谷雨","卯时","4","20","5","18"}}//数据太多,粘贴部分为例

    数据封装model中如下:

    namespace suwenhua.Models
    {
        public class LaoHuangLi_Models
        {
            public string YangLiNian{get;set;}
            public string YangLiYue{get;set;}
            public string YangLiRi{get;set;}
            public string NongLiShuXiang{get;set;}
            public string NongLiNianJiaZi{get;set;}
            public string NongLiNianTaiSui{get;set;}
            public string NongLiNianJiuXin{get;set;}
            public string NongLiYueFen{get;set;}
            public string NongLiYueDaXiao{get;set;}
            public string NongLiYueJiaZi{get;set;}
            public string NongLiYueJiuXin{get;set;}
            public string NongLiYueBaGua{get;set;}
            public string NongLiYueErShiBaXiu{get;set;}
            public string NongLiRi{get;set;}
            public string NongLiRiJiazi{get;set;}
            public string NongLiRiJiuXin{get;set;}
            public string NongLiRiJianChuShiErZhi{get;set;}
            public string NongLiRiErShiBaXiu{get;set;}
            public string NongLiErShiSiJieQi{get;set;}
            public string NongLiErShiSiJieQi_ShiChen{get;set;}
            public string NongLiErShiSiJieQi_YangLiYue{get;set;}
            public string NongLiErShiSiJieQi_YangLiRi{get;set;}
            public string NongLiErShiSiJieQi_Shi{get;set;}
            public string NongLiErShiSiJieQi_Fen{get;set;}
            public string NongLiErShiSiJieQi_1{get;set;}
            public string NongLiErShiSiJieQi_ShiChen_1{get;set;}
            public string NongLiErShiSiJieQi_YangLiYue_1{get;set;}
            public string NongLiErShiSiJieQi_YangLiRi_1{get;set;}
            public string NongLiErShiSiJieQi_Shi_1{get;set;}
            public string NongLiErShiSiJieQi_Fen_1{get;set;}
        }
    }

    2018年12月20日 13:16
  • 后台  controller

     [RoutePrefix("Purchasing/PurchaseOrder"), Route("{action=index}")]    
        public class PurchaseOrderController : Controller
        {
            public ActionResult Index()
            {

                 LaoHuangLi_Models  model=new ..

                 model.YangLiNian="ABC"; 

                 .....

                 return View("~/Modules/Purchasing/PurchaseOrder/PurchaseOrderIndex.cshtml",model);
            }
        }

    前台页面cshtml

    @model  suwenhua.Models.LaoHuangLi_Models
    @{
        ViewData["Title"] = "Dashboard";
        ViewData["PageId"] = "Dashboard";
    }

    <div class="row">
               <h4>@Model.YangLiNian</h4>    这个地方就会显示值ABC
         </div>
                    
                      



      


    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms



    2019年10月20日 7:39