本文介绍了列表与LT;视图模型>在视图对象中返回null - 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究MVC 5,有一个viewmodel类,并且包含一个虚拟列表作为同一个类。



发生问题,问题填写清单现在是空的。请帮帮我先生...



我写的: - PartnerProjectVM partnerProjectVM = new PartnerProjectVM();



没有使用这个新的关键词如何访问我的列表?意思是'partnerProjectVM.listPartnerProjectVM'就像这样



我尝试过:



Viewmodel,



  public   class  PartnerProjectVM 
{
public int idPartnerProject {获取; set ; }
public string ProjectName { get ; set ; }
public string ProjectDescription { get ; set ; }
public virtual 列表< PartnerProjectVM> listPartnerProjectVM { get ; set ; }
}





获取/发布方法,



 [HttpPost] 
public ActionResult PremiumUserRegProjects(PartnerProjectVM partnerProjectVM
{
partnerProjectVM.listPartnerProjectVM = new 列表< PartnerProjectVM>();
partnerProjectVM.listPartnerProjectVM.Add(partnerProjectVM);
return RedirectToAction( PremiumUserRegProjects);
}

[HttpGet]
public ActionResult PremiumUserRegProjects()
{
PartnerProjectVM partnerProjectVM = new PartnerProjectVM();
if (partnerProjectV) M.listPartnerProjectVM!= null && partnerProjectVM.listPartnerProjectVM.Count()> 0
{
var lastItemProject = partnerProjectVM.listPartnerProjectVM.LastOrDefault();

partnerProjectVM.ProjectName = lastItemProject.ProjectName;
partnerProjectVM.ProjectDescription = lastItemProject.ProjectDescription;


return 查看( PremiumUserRegProjects,partnerProjectVM);
}
}
解决方案

I'm working on MVC 5, there is a viewmodel class and contain a virtual list as the same class.

Issue occurred, the problem is filled list is now empty. please help me sir...

I did write:- PartnerProjectVM partnerProjectVM = new PartnerProjectVM();

with out using this new key word how can I access my list? mean, 'partnerProjectVM.listPartnerProjectVM' like this

What I have tried:

Viewmodel,

public class PartnerProjectVM  
   {  
       public int idPartnerProject { get; set; }  
       public string ProjectName { get; set; }  
       public string ProjectDescription { get; set; }  
      public virtual List<PartnerProjectVM> listPartnerProjectVM { get; set; }  
   }  



Get/Post Method,

[HttpPost]  
        public ActionResult PremiumUserRegProjects(PartnerProjectVM partnerProjectVM  
        {  
             partnerProjectVM.listPartnerProjectVM = new List<PartnerProjectVM>();  
                partnerProjectVM.listPartnerProjectVM.Add(partnerProjectVM);  
                return RedirectToAction("PremiumUserRegProjects");  
        }  
          
         [HttpGet]  
        public ActionResult PremiumUserRegProjects()  
        {  
             PartnerProjectVM partnerProjectVM = new PartnerProjectVM();  
             if (partnerProjectVM.listPartnerProjectVM != null && partnerProjectVM.listPartnerProjectVM.Count() > 0)  
            {  
              var lastItemProject = partnerProjectVM.listPartnerProjectVM.LastOrDefault();  
  
                partnerProjectVM.ProjectName = lastItemProject.ProjectName;  
                partnerProjectVM.ProjectDescription = lastItemProject.ProjectDescription;  
                
  
                return View("PremiumUserRegProjects", partnerProjectVM);  
            }  
        }  
解决方案


这篇关于列表与LT;视图模型&GT;在视图对象中返回null - 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 13:43