Question

All the documentation I have found, and that is lots, shows how to create a content type, capture documents of that content type using the Umbraco UI, and how to create templates to display that document.

I'm sure I need a POST action, which will get a view model reflecting the content type structure; it's variables and other content, but where to find this and what to do with the data remain a mystery to me.

How do I create a document capture view, as well as the so common display view?

Was it helpful?

Solution

It's fairly easy to create a form that POSTs to a surface controller. There is a very good tutorial in the Our Umbraco community website which may be useful to you. You can find the tutorial here.

Inside the controller action that handles the POST, you need to add a call to the Umbraco Management API, which is used for CRUD operations.

Here's an example of how to create and populate the properties of a content document in Umbraco 6+:

private void AddProduct(int productId, string name, int productGroupId, int price)
    {
        // Get the Umbraco Content Service
        var contentService = Services.ContentService;

        var product = contentService.CreateContent(
            name,           // the name of the product document
            productGroupId, // the parent id should be the id of the group node 
            "product",      // the alias of the product Document Type
            0);

        // Here's how to update some of the properties
        product.SetValue("productId", productId);
        product.SetValue("originalName", name);
        product.SetValue("priceDKK", price);

        // finally we need to save and publish, this saves the product and the property values
        contentService.SaveAndPublish(product);
}

There are similar services for Media, Files, DataTypes etc. For more info, have a look here for Umbraco v6+ and here for earlier versions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top