Copied to clipboard

Flag this post as spam?

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


  • Conor 4 posts 74 karma points notactivated
    1 week ago
    Conor
    0

    Hi,

    I have a view whereby I currently inherit from the default model. My page is called 'Our Products Page' so it inherits from ContentModels.OurProductsPage.

    I am using code in here that needs the fields in this model. I have code such as:

            var selection = Model.Content.Site().FirstChild("ourProductsPage").Children()
                        .Where(x => x.IsVisible());
    

    I need to add a form to this page, whereby I can access the data the user submits in this form, and then process this in functions that I have in the view.

    I have a feeling it means I will have to create my own controller and viewmodel for this page, and pass the data into my viewmodel which can then be used in this view. However I also need the current viewmodel so that I can access 'Model.Content.Site()...'.

    Is there any way I can simply add a form to this page, allow the user to enter details, and when they submit it the data will be passed with the current viewmodel back to this page so that I can use the data in the functions I have?

    Any guidance appreciated.

  • Lewis Smith 65 posts 274 karma points
    1 week ago
    Lewis Smith
    0

    Hi Conor,

    To set up a form you will need to either use the Umbraco Froms plugin (paid) or as you said need to set up a model and a controller.

    Code share has a good tutorial on the basics of this: http://www.codeshare.co.uk/blog/how-to-create-a-contact-form-in-umbraco-using-mvc-and-c/

    The function you are talking about in the view to process this data will probably need to be added to the controller along side the functions that submit the form.

    Is this what you are after?

    Thanks, Lewis

  • Conor 4 posts 74 karma points notactivated
    1 week ago
    Conor
    0

    Hey Lewis,

    Thanks for the response and for the handy video there.

    I wasn't very clear in my last message, so I want to try and clarify something that is concerning me.

    If it is the case that I need to add my own custom model, controller and view, I am worried that I will lose functionality in my current view which uses fields in the 'Umbraco.Web.Mvc.UmbracoTemplatePage' model.

    Ideally, I want to just add two variables within this view model which a form would then populate, so once submitted I could access these values. Is there any way I can edit this view model that already exists, and the action method within the already existing controller, so as to incorporate the form values? I could then access these on the page by inheriting from this same model.

    However - if that is not possible, would it be possible to create my own custom model/controller, but then have a property in here that holds the OurProductsPage data also?

    To put it more simply... I need to access both my own custom variables in the viewmodel, AND the fields I am already accessing through the model OurProductsPage.

    Sorry if this is confusing, I'm not very familiar with umbraco and not an expert with MVC, I just know enough to get by haha.

    Thanks for any further advice.

Please Sign in or register to post replies

Write your reply to:

Draft