Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 have placed 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

What I have tried:

This is what I have tried

C#
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);
}


HTML
@Html.Partial("~/Views/LogoImage/UploadImage.cshtml",Model)
Posted
Updated 27-Dec-23 5:52am
v3
Comments
[no name] 27-Dec-23 13:50pm    
Your arbitrary use of upper and lower case and mismatched variable names makes everything highly confusing. Not to mention the pointless layering of classes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900