November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi!
Where did you add that field? When a page is published in Episerver it does not post the entire page in a form.
Couldn't you add a property to the page type instead and hide it away on some tab? You can always null the value after publishing.
[Display(GroupName = SystemTabNames.Settings)] public virtual string MyFieldProperty { get;set; }
And in your view you could have:
if (PageEditing.PageIsInEditMode) { @Html.PropertyFor(m => m.MyFieldProperty) }
When the page is published:
DataFactory.Instance.PublishingContent += OnPublishingContent; private void OnPublishingContent(object sender, ContentEventArgs contentEventArgs) { var page = e.Content as MyPageType; var myField = page.MyFieldProperty; // Do stuff with your value // If you don't want to persist the value on the page: page.MyFieldProperty = null; }
Thanks Mattias. For testing I had created a HomePage page model and controller, and then placed that field into the HomePage Index view.
We don't need to hide the field. We are looking for additional ways to apply custom logic to entered values when they are published. With standard MVC it's a straightforward process to capture and manipulate (or store) field data when a form is submitted. But this part -- When a page is published in Episerver it does not post the entire page in a form -- we did not know. What you suggested may be the direction we'll need to take. In the past I used a pattern like that to adjust XhtmlString markup in the SavingContent event.
Is there a way to signal to the CMS that we would like a field to be captured at publish or save without making that field a property of the page type?
Recently I had a request to add an input field to a page that is presented in the CMS, but to not define that field as a page property, with the goal being to capture that value on the back end when the page gets published. To do this, I added an OnPublishedContent event in the Global.asax, and then expected to see it in the ContentEventArgs object or in the HttpContext.Current.Request. But at this point I'm not able to capture the value from this form field.
Here is the code in my Global.asax with a couple of attempts that did not return the expected value from "MyField".