#StackBounty: #c# #.net #asp.net-mvc #model Build a Layout ViewModel based in a Id from the URL with MVC

Bounty: 50

I need to build a ViewModel for my Layout’s Web Application, I have tried this solution but it’s not based on a URL’s Id coming from the URL to generate the Layout’s ViewModel.

I tried this but I first had the not existing empty controller error, then I tried to include the id as a parameter but I get the error “Object reference not set to an instance of an object.” because the LayoutColorRGB is not set.

public MobileController(int id)
{
    Event model = db.Events.Where(s => s.Id == id).FirstOrDefault();

    LayoutVM = new LayoutVM()
    {
        EventId = model.Id,
        LayoutColorRGB = model.LayoutColorRGB,
        SponsorLogoLink = model.SponsorLogoLink,
        SponsorLogoURL = model.SponsorLogoURL
    };

    ViewData["LayoutVM"] = LayoutVM;
}


Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.