Quantcast
Channel: Using Optimizely Platforms
Viewing all articles
Browse latest Browse all 8020

UrlResolver instance is null

$
0
0

Hi,

I am trying to get a friendly-url for a page of type ContentReference (property in site settings) in another page's controller.

In site settings:

public virtual ContentReference NewsletterSuccessPageRef { get; set; }

In the base controller I am populating the "Model" in override method OnActionExecuting():

protected override void OnActionExecuting(ActionExecutingContext filterContext)
		{
			base.OnActionExecuting(filterContext);
			var currentPage = filterContext.ActionParameters.First(ap => ap.Value is TPage).Value as TPage;
			var currentContent = filterContext.ActionParameters.First(ap => ap.Value is TContent).Value as TContent;
			Model = filterContext.ActionParameters.FirstOrDefault(ap => ap.Value is TViewModel).Value as TViewModel;
			InitializeModel(currentPage, currentContent);
		}

Other page's controller:

var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();
var url = urlResolver.GetUrl(Model.SiteSettings.NewsletterSuccessPageRef);

But I get a NullReference exception on line 21:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error: 
Line 19: 
Line 20: 			var urlResolver = ServiceLocator.Current.GetInstance<IUrlResolver>();
Line 21: 			var url = urlResolver.GetUrl(Model.SiteSettings.NewsletterSuccessPageRef);
Line 22: 

Debugging shows that neither the "urlResolver" nor the "SiteSettings.NewsletterSuccessPageRef" are null.

Any ideas why?

Regards,

Micha


Viewing all articles
Browse latest Browse all 8020

Trending Articles