pageTypeName null, Object reference not set to an instance of an object

We have a custom product creation page, this page create a product and you have two option, save the product or save the product and add pictures.

When saving the product and add pictures in the controller: CreateProductController, we send the product object to a new view (other custom page), so there we can add files(pictures) to the product.

We do it like this:

// Return FindProductView if save and continue
if (productModel.UploadImages)
{
   var modelFindProduct = new FindProductViewModel();
   modelFindProduct.SavedProduct = productModel;
   return View("~/Views/FindProduct/Index.cshtml", modelFindProduct);
}

In this page, the the user add the files and save it, other functionality of this same custom page (FindProduct) is if the user go directly to the page then it shows first a search so the user can search for a product and if the search finds a product then the upload files part it is shown and do the same thing to save the pictures for that product.

case 1. Go to the addpictures custome page (FindProduct) → search and find a product → select images from your local computer, click save. All works fine. controller name: FindProductController

case 2. From the create product controller after creating the product we call the view to upload files(FindProduct), the view loads, we get the product object, so the search part is not display only the upload files part is display, then when saving the images all works, if I see in the Litium admin, the product was created, the images where uploaded and assigned to the product but after all logic is done we get this error:

Object reference not set to an instance of an object.

Line 93: var pageTypeName = context.CurrentState.PageType.Name;

Any ideas what we are missing?

Litium version: 6

This is for Litium 6, right?

Are these custom pages actual pages in the Litium CMS? How are they accessed?
It seems like you’re coming in through the routing in Litium, and it can’t find the page type.

The current state was removed in Litium 7. Is the exception (stack trace) from platform or solution code?

Hi NilsN,

Yes sorry it’s: Litium Version: 6.
The pages are pages in the litium CMS, the user access them in the website menu not the cms admin (we show them using a custom menu).

Yes the version is litium 6

From the controller that calls to the new view using the full address like this works:

return Redirect(“https://localhost.erik/sokbefintligaprodukter?articleId=” + productModel.ArticleId.Trim() + “P”);

But if we send it like this, is not working: return View("~/Views/FindProduct/Index.cshtml", modelFindProduct);

This is in our development environment, that why we use localhost.

If you request a controller that not is mapped to a page in the website, then the CurrentState is not set and the view can not render itself. When you doing the redirect the user is redirected to the page that exists in the website and the needed CurrentState is set with the page information.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.