Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object reference not set to an instance of an object in NoScript.cshtml #104

Closed
shakibmiraki opened this issue Dec 20, 2016 · 8 comments
Closed

Comments

@shakibmiraki
Copy link

i created a form in my Home Document Type and put it in my layout page to render in every pages,
it works well on the home page but give me the "Object reference not set to an instance of an object" error in NoScript.cshtml
is this my wrong or an issue ?

@kjac
Copy link
Owner

kjac commented Dec 20, 2016 via email

@shakibmiraki
Copy link
Author

no i name it form, but this is the error on every page except home page that i created the form in this document type.
capture
object reference not set to an instance of an object

@kjac
Copy link
Owner

kjac commented Dec 20, 2016 via email

@kjac
Copy link
Owner

kjac commented Dec 20, 2016

Hi @shakibmiraki,

It looks like Umbraco isn't initializing a FormModel instance when there's no form defined on the document type or content (e.g. on the child pages to your home page).

Could you please try changing line 11 in /Views/Partials/FormEditor/NoScript.cshtml to this:

var form = formContent.GetPropertyValue<FormModel>(formPropertyName) ?? new FormModel();

If that works I'll update the default views to handle this situation more gracefully.

@shakibmiraki
Copy link
Author

Hi @kjac
after changing this line i get another error.
object reference not set to an instance of an object

@kjac
Copy link
Owner

kjac commented Dec 20, 2016

@shakibmiraki excellent. At least I know where the problem lies then.

I think this is caused because you're calling the Form Editor partial (NoScript.cshtml) while rendering a page that does not contain a Form Editor property. You mentioned that you're calling it on every page, but that the Form Editor property is only on your Home page? You shouldn't call it unless you have a Form Editor property to render.

If you're trying to render the Form Editor property from your Home page on every page, you should take a look at this documentation or this tutorial.

In any case I will update the default views to counter for this problem in the next release, so the site doesn't crash.

kjac pushed a commit that referenced this issue Dec 20, 2016
@shakibmiraki
Copy link
Author

yes @kjac that works for me.
my fault.
thanks you.

@kjac
Copy link
Owner

kjac commented Dec 21, 2016

@shakibmiraki glad to hear that... and thank you for bringing the issue to my attention. I'll make sure the bundled views take this situation into account in the next (imminent) release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants