Model is null while rendering view

15 Views Asked by At

I have a child view name UploadImage and parent view name CROCOnfig, when I access child view by using button in parent view,it works fine, but when I try to render child view in parent view,it throws error that model is null. I am placing child view model in parent view model. I have debug the code line by line,but could not figure out the reason, I am sharing some of my code below,

public CombinedLogoModel LogoModel {get;set;} this line says LogoModel is null while rendring view

This is what I have tried

   public class VM_LogoImageModel : ModelBase
    {
        //private ILogoImageRepository LogoImageRepo = null;

        #region Table Attribute LogoImage 
        public int ImageId { get; set; }
        public string FileOriginalName { get; set; }
        public string FileName { get; set; }
        public string Title { get; set; }
        public Nullable<bool> IsDeleted { get; set; }
        public Nullable<bool> IsActive { get; set; }
        public Nullable<int> LogoType { get; set; }
        public Nullable<int> FileExtension { get; set; }
        public int CROID { get; set; }

        //public VM_CRO RMO_CRO { get; set; }


        #endregion


    }
    #endregion


    public class CombinedLogoModel
    {
        public IEnumerable<VM_LogoImageModel> LogoImageModels { get; set; }
        public VM_LogoImageModel SingleLogoImageModel { get; set; }


    }
public class VM_CROPortalCOnfiguration{
public CombinedLogoModel LogoModel {get;set;}
}
 public ActionResult UploadImage()
        {
            var AllLogos = logoImage.GetAllLogos();

            var AllLogosViewModels = AllLogos.Select(Mapper.MapToVM_LogoImageModel).ToList();

            var LastUploadedLogos = VM_LogoImageModel.GetLastUploadedLogos(AllLogosViewModels);

       //some other code
            var CombinedViewModel = new CombinedLogoModel
            {
                LogoImageModels = LastUploadedLogos,
                SingleLogoImageModel=LastUploadedLogos.FirstOrDefault()
            };


            var CroPortalCombined = new VM_CROPortalConfiguration
            {
                LogoModel = CombinedViewModel
            };
            
            return View("UploadImage", layout, CroPortalCombined);
        }
0

There are 0 best solutions below