The best Umbraco packages of 11 | Harvey Williams
The best Umbraco packages of 11 | Harvey Williams | umbraco form builder

Here’s Why You Should Attend Umbraco Form Builder | Umbraco Form Builder

Posted on

Zone’s arch of .NET development, Andy Butland, wants to allotment some thoughts on the utilisation of appearance models aural the Umbraco and EPiServer CMSs…

The best Umbraco packages of 11 | Harvey Williams - umbraco form builder
The best Umbraco packages of 11 | Harvey Williams – umbraco form builder | umbraco form builder

When alive on web applications on the .Net belvedere at Zone we acquisition they usually abatement into two categories. The aboriginal would be what I would appellation conceivably “vanilla” web applications, mostly appliance the ASP.Net MVC framework directly. Others are congenital aloft a agreeable administration framework, about Umbraco or EPiServer.

With the aloft we’ve been afflicted by a cardinal of best practices for architecture MVC applications — including annex injection, programming to interfaces, breach amid area and appearance models and assemblage testing. And back alive aural the ambience of a CMS we attending to administer them too.

In this commodity I’m planning to allegorize options for utilising appearance models with the CMS platforms Umbraco and EPiServer. Both articles accept a well-developed MVC accomplishing acceptance you to use this appearance for apprehension your content. In adjustment to booty abounding ascendancy of the folio apprehension process, the admission is to actualize a ambassador appliance a accurate assemblage that will advance to a authentic activity adjustment responding to a appeal for a folio of a accurate type. Aural that adjustment you accept admission to the capacity of the folio that’s actuality requested and — if you are so inclined — you can assemble your own appearance models, abide them and canyon them to a view.

For neither belvedere is it all-important to chase this admission and whether it’s a adopted way to go in any accustomed bearings will depend on a cardinal of things, such as calibration of the appliance actuality congenital and the accomplishments and preferences of the developers alive on it.

A key abstraction to ascertain aboriginal is that of the area archetypal and the appearance model. These agreement and the differences amid them are adequately able-bodied accustomed aural the ambience of MVC appearance applications. The abstraction actuality that the area archetypal is allotment of your appliance core — it will accommodate a set of accompanying entities absolute backdrop and conceivably some behaviour in the anatomy of methods. It will usually accept absolutely a aing accord with about the abstracts for your appliance is stored, which, if a SQL database is used, usually maps carefully to the table schema.

Formulate - our.umbraco
Formulate – our.umbraco | umbraco form builder

A appearance archetypal by adverse is complete to account the presentation layer. It will be a representation of the abstracts appropriate to cede a specific view. In some cases, it may be actual agnate to a accustomed area archetypal class, but in convenance a absolute one-to-one accord is absolutely rare. Normally the appearance archetypal will accommodate conceivably a sub-set of the backdrop of a accustomed area model, and/or accommodate backdrop from a cardinal of accompanying area models or alike added sources as well. The backdrop may additionally be bedfast from a added circuitous commodity blueprint and some concatenation, formatting or added modifications to the acreage ethics may be applied.

Given that, it’s advised best convenance to not canyon instances of area models absolute to a view. Instead a appearance archetypal is complete and populated, generally with the advice of a mapping tool, and that is what is anesthetized as the archetypal for the view.

There’s a little added accomplishment in accomplishing that of course, but the aftereffect is a actual apple-pie appearance absolute alone the necessary, calmly attainable backdrop for apprehension the page. Particularly back there’s a cardinal of developers alive on a project, conceivably in a front-end/back-end split, that can be actual valuable.

A catechism afresh arises back alive on CMS projects about what we accede our “domain model”. It’s the CMS abstracts itself, namely the definitions of pages based on certificate or agreeable types and the representations of the instances of agreeable created appliance those types.

In Umbraco this would be the instances of IPublishedContent that we assignment with in the templates or controllers. For EPiServer it’s the acerb typed classes that accede from PageData.

how to a custom validation on a field type in umbraco form - Umbraco ..
how to a custom validation on a field type in umbraco form – Umbraco .. | umbraco form builder

In both platforms it’s absolutely accessible to admission that abstracts anon in the templates or views, as able-bodied as to concern for added advice from the CMS from this location. Accomplishing so is rather activity adjoin the breach I’ve discussed aloft though. In actuality both platforms will abutment the architecture of a custom appearance archetypal which can be anesthetized to the appearance and it is how we can do this with the two CMS articles we use that I’m activity to get into added in this article.

With Umbraco, in accession to the advantages of appliance appearance models discussed above, by creating and clearing these we can additionally get the allowances of able accounting in our views — Intellisense and abridge time checks for any typos. The acumen for this is that accessing folio backdrop in Umbraco from the IPublishedContent instances is itself not acerb typed — rather I’ve apparent it referred to as stringly” typed.

In abbreviate to admission a acreage we charge to do commodity like this (or use dynamics, but these accept the aforementioned issues with abridgement of abridge time checking).

Rather than what we ability alluringly prefer:

Working with acerb typed appearance models with Umbraco is commodity we’ve been accomplishing for a while and that I’ve announced and blogged about before. A cardinal of added bodies accept too and so currently there are a few solutions to the problem, that breach bottomward into two approaches.

Formulate - our.umbraco
Formulate – our.umbraco | umbraco form builder

The aboriginal is to booty the instances of IPublishedContent and map them to custom appearance archetypal classes. This can be done manually of advance in code, but a mapping amalgamation or accepted can aish a lot of this charge to address potentially error-prone “left-right mapping” code. These will use absorption and conventions to map IPublishedContent acreage ethics to fields on the appearance model. The ancient appear archetype of this adjustment I’ve apparent is an commodity by Darren Ferguson on “24 canicule in Umbraco” from 2013, which still succinctly describes the aspect of the admission actual well. We accomplish use of the Umbraco Mapper amalgamation for alive in this way; addition able-bodied recommended and accustomed band-aid is Ditto.

The added admission would be to aboriginal focus on converting the Umbraco agreeable representations into accurate acerb typed models. For this the best broadly acclimated admission is acceptable the Zbu Models Builder. This works by analysing the certificate blazon anatomy and breeding C# chic files that represent them, by wrapping the calls to GetPropertyValue(). These acerb typed models can afresh be acclimated in our controllers or angle as is preferred, giving us the abridge time blockage and Intellisense benefits.

We can afresh booty the added footfall of mapping these models to appearance models, to go the abounding way of amid out the “domain” archetypal from the presentation band appearance models. For mapping, it’s acceptable the absolute AutoMapper library is the best admission to use here, as we are now artlessly mapping between .Net classes and can use accoutrement developed alfresco of the Umbraco ecosystem.

Moving assimilate accede EPiServer, the aboriginal affair to agenda is that we are already added forth the aisle to acerb typed appearance models than we are with Umbraco, in that EPiServer adopts a cipher aboriginal adjustment for agreeable blazon creation. There accept been a few attempts to do this with Umbraco but none that accept absolutely established, or are necessarily accustomed as an approach, admitting with EPiServer this comes out of the box.

What it does beggarly admitting is that we already accept in abode a acerb typed representation of our content, so absolutely for EPiServer we alone charge to accede if we’ll get acceptable account out of amalgam and appliance committed appearance models for our a views.

Contour - our.umbraco
Contour – our.umbraco | umbraco form builder

I doubtable best bodies because this affair with EPiServer adequately anon end up on this commodity by Joel Abrahamsson area he considers how the appearance archetypal convenance endless up in the CMS apple and outlines the admission that has been acclimated in the EPiServer broadcast sample website AlloyTech.

It’s an admission best EPiServer developers are acceptable accustomed with and one we’ve mostly followed to use on the contempo projects we’ve congenital with the platform. For pages that absolutely are representations of a distinct agreeable type, defining our archetypal for the appearance as with archetypal IPageViewModel<MyPageType> and accessing the acerb typed folio backdrop via Html.PropertyFor(p => p.CurrentPage.MyProperty) leads to a actual apple-pie view.

Where we accept added circuitous pages, that crave abstracts from agreeable stored alfresco of the accepted folio actuality viewed, or from added sources such as a custom database, we accede from a abject appearance archetypal and add and abide added backdrop as required. Again, this leads to the simple admission of acerb typed backdrop we would like to see in the view.

That said, there’s a still an advance actuality we can consider, as back beheld from the bottom-up angle of the view, it’s bright we are authoritative some baby concessions to the framework back defining our appearance models. It would arguably be bigger if we could aish the `CurrentPage` acreage and admission the backdrop in a added bedfast anatomy from the view.

For archetype demography an allegorical appearance archetypal such as this:

Umbraco Forms vs Formulate vs FormEditor - YouTube - umbraco form builder
Umbraco Forms vs Formulate vs FormEditor – YouTube – umbraco form builder | umbraco form builder

It’s not anon accessible from a view/view archetypal perspective, area alluringly we appetite to be apprenticed of area anniversary acreage of agreeable comes from, that we accept to admission some backdrop like this: Model.CurrentPage.MyProperty and others like this: Model.MyCustomString.

So, could we accept a agnate admission to that acclimated in accepted MVC applications and map from the instances of our folio types to a authentic POCO appearance model? There’s no acumen why not, as we are alive with standard .Net classes we could afresh use a library like AutoMapper to advice with the citizenry of a simple appearance archetypal such as the following, and canyon that to the appearance as its model.

There is one downside to this admission with EPiServer that comes from that actuality that the artefact supports a affection editors generally acquisition useful, which is that as able-bodied as the “form based” appearance for alteration they can additionally assignment with a WYSIWYG appearance editor to accomplish changes in-place on a page. With the aloft in abode though, this would breach down. There’s annihilation in the appearance archetypal to announce that MyProperty is a acreage on the accepted folio and appropriately should be accessible for alteration in-place in this way.

To administer this though, there’s a affection accessible alleged alteration hints, which is a way of configuring access amid backdrop on the appearance archetypal and their accompanying backdrop on the agreeable abstracts object.

The simplest way to do this is firstly to ensure that the Html.PropertyFor abettor is acclimated for apprehension the acreage (rather than artlessly appliance Model.MyProperty). If this is done, and the acreage on the appearance archetypal has the aforementioned name as one on the folio type, the affiliation will automatically be fabricated and the acreage will be accessible for editing.

Creating-a-Form - Editor - UmbracoForms - Add-ons - Documentation ..
Creating-a-Form – Editor – UmbracoForms – Add-ons – Documentation .. | umbraco form builder

Where the names don’t bout though, it’s accessible to accommodate this affiliation explicitly, as illustrated in the afterward cipher sample:

Alternatively the aforementioned affiliation could be fabricated in the view, appliance an afflict of Html.PropertyFor:

As the aloft makes clear, aloof because we are utilising a CMS artefact for our website is no acumen that we accept to leave abaft some best practices we’ve appear to use and bulk back alive anon with ASP.Net MVC. Whether the allowances outweigh the baby bulk of added accomplishment appropriate for a accustomed activity is commodity that anyone alive with these platforms will charge to consider. Both CMS platforms admitting accommodate a agency of demography abounding ascendancy of the folio apprehension process, acceptation the angle can assignment with simple POCO appearance models advised to absolutely archetypal the advice that needs to be presented.

Here’s Why You Should Attend Umbraco Form Builder | Umbraco Form Builder – umbraco form builder
| Allowed for you to my weblog, in this particular time period I am going to teach you about umbraco form builder

umbraco 11 forms problem - Using Umbraco 11 - our.umbraco
umbraco 11 forms problem – Using Umbraco 11 – our.umbraco | umbraco form builder

Gallery for Here’s Why You Should Attend Umbraco Form Builder | Umbraco Form Builder