Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • James Paquette 8 posts 38 karma points
    Nov 20, 2017 @ 21:45
    James Paquette

    Creating Custom Forms in Umbraco 7

    I am upgrading our website to Umbraco 7 from Umbraco 4. In the older version I had created a number of custom forms out of user controls in .NET. These would handle pretty complex interactions and work with our database. As I am migrating to Umbraco 7 I have discovered that these forms will no longer work because Umbraco 7 uses Mvc and not Web forms.

    My first question is, do I understand this accurately?

    I've spent the day under the assumption that I'm going to have to rewrite all my forms as Mvc but I cannot find a good step by step tutorial on how to do it. I've gotten as far as staring a model and a surface controller, but I don't understand how to make it render on the site. Before I would just drop the user control and dll into the appropriate folders and reference it with a macro, but I don't know how to do this with the Mvc format.

    I understand that I have to create a view but do I do this in visual studio and place it in the views folder like I used to do with the user control and reference with a macro somehow?

    Should I install Umbraco into Visual Studio to get this working even though my site stands alone on another server?

    If I have to install Umbraco into Visual Studio, what files do I need to move over to my site after compilation to get it to work?

    I just became familiar with Mcv today, so pardon my ignorance if I don't have something right.

    Thanks for any help you can provide!

  • Alexander Croner 71 posts 282 karma points
    Nov 21, 2017 @ 08:51
    Alexander Croner
    1. Create a controller that inherit from surfaceController
    2. Let the action in that controller have a viewmodel which fits your datamodel
    3. Render the form in a macro or in a template using something like this (where my action-name is 'Submit' and my controller named 'Feedbackformcontroller'):

      using (Html.BeginUmbracoForm("Submit", "FeedbackForm"))

    And render the fields with normal mvc 'textboxfor' for your viewmodel which you declared in the top of your view.

    Good luck!

  • James Paquette 8 posts 38 karma points
    Nov 21, 2017 @ 21:48
    James Paquette

    I've been trying to render the form in a macro but I keep getting a "Cannot bind source type Umbraco.Web.Models.PartialViewMacroModel to model type MyModel.Models.ContactModel."

    I think given my inexperience with MVC, maybe I should start small with this specific problem:

    1) I want to build a simple form with a submit button that will print "hello world" on a post back.

    2) I want to be able to put this form in a macro so that I can drop it on any page of my website (I don't want to use a template because I have a few forms I'll eventually have to convert and I don't want to have to create a template for each form).

    Every tutorial I've read shows me how to build the model, and the surface controller. It seems I am doing that correctly because I can get my project to build. However I haven't found anything on how to get the view to render in a macro so I can drop the form on any page I need.

  • Alexander Croner 71 posts 282 karma points
    Nov 22, 2017 @ 07:56
    Alexander Croner

    I think you need to start learning some MVC in order to get what you are doing.

    Anyhow, here is a tutorial from Paul Seal which explains it

Please Sign in or register to post replies

Write your reply to: