Copied to clipboard

Flag this post as spam?

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


  • mikkel 143 posts 365 karma points
    Dec 26, 2018 @ 06:25
    mikkel
    0

    why can i not use: using InstallUmbraco.Models;

    Hi I am trying to make the contact form from poul seals video https://www.youtube.com/watch?time_continue=41&v=3V0A1AYJbys But i am stuck in the part where i have to make a partial view where i want me to use this code, i cant use any of them i get errors. I was thinking that it is and old video so something has change but i can not find out what ??

    what to do and what to use??

    @inherits UmbracoViewPage<InstallUmbraco.Models.KontaktModel>
    
    @using (Html.BeginUmbracoForm("SubmitForm", "KontaktSurface", FormMethod.Post))
    

    You can se the code here at pouls website https://codeshare.co.uk/blog/how-to-create-a-contact-form-in-umbraco-using-mvc-and-c/

  • mikkel 143 posts 365 karma points
    Dec 26, 2018 @ 07:03
    mikkel
    0

    I got it. I was missing this in my model

    namespace InstallUmbraco.Models
    

    But now i get this error and i dont no what to do with it

    Additional information: Cannot bind source type Umbraco.Web.Models.RenderModel`1[[Umbraco.Web.PublishedContentModels.Forside, 
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Dec 26, 2018 @ 10:05
    Alex Skrypnyk
    0

    Hello Mikkel

    Something wrong with doctype you are on. Can you show all the code and tell me what doctype current page?

    Alex

  • mikkel 143 posts 365 karma points
    Dec 27, 2018 @ 11:36
    mikkel
    0

    Hi Alex I was testing it on my forside ( frontpage ) template just to see if it works.

    Frontpage template code

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Forside>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "Master.cshtml";
    }
    
    @Html.Partial("kontakt/_Kontakt")
    

    This here is the form i want to show and it is also the PartialView code

    @inherits UmbracoViewPage<InstallUmbraco.Models.KontaktModel>
    
    @using (Html.BeginUmbracoForm("SubmitForm", "KontaktSurface"))
    {
        @Html.AntiForgeryToken()
    
        <div class="form-group">
            @Html.ValidationSummary()
        </div>
    
        <div class="form-group">
            <div class="col-xs-3">
                @Html.LabelFor(m => m.Fornavn)
            </div>
            <div class="col-xs-9">
                @Html.TextBoxFor(m => m.Fornavn)
            </div>
        </div>
    
        <div class="form-group">
            <div class="col-xs-3">
                @Html.LabelFor(m => m.Efternavn)
            </div>
            <div class="col-xs-9">
                @Html.TextBoxFor(m => m.Efternavn)
            </div>
        </div>
    
        <div class="form-group">
            <div class="col-xs-3">
                @Html.LabelFor(m => m.EmailAddresse)
            </div>
            <div class="col-xs-9">
                @Html.TextBoxFor(m => m.EmailAddresse)
            </div>
        </div>
    
        <div class="form-group">
            <div class="col-xs-3">
                @Html.LabelFor(m => m.Besked)
            </div>
            <div class="col-xs-9">
                @Html.TextAreaFor(m => m.Besked)
            </div>
        </div>
        <button>Submit</button>
    }
    

    My kontaktSurfaceController code

    using Umbraco.Web.Mvc;
    using System.Web.Mvc;
    using InstallUmbraco.Models;
    using System.Net.Mail;
    using WebManden.Models;
    
    namespace InstallUmbraco.Controllers
    {
        public class KontaktSurfaceController : SurfaceController
        {
            public const string PARTIAL_VIEW_FOLDER = "~/Views/Partials/kontakt/";
            public ActionResult RenderForm()
            {
                return PartialView(PARTIAL_VIEW_FOLDER + "_Kontakt.cshtml");
            }
    
            [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult SubmitForm(KontaktModel model)
            {
                if (ModelState.IsValid)
                {
                    SendEmail(model);
                    TempData["ContactSuccess"] = true;
                    return RedirectToCurrentUmbracoPage();
                }
                return CurrentUmbracoPage();
            }
    
            private void SendEmail(KontaktModel model)
            {
                MailMessage message = new MailMessage(model.EmailAddresse, "[email protected]");
                message.Subject = string.Format("Enquiry from {0} {1} - {2}", model.Fornavn, model.Efternavn, model.EmailAddresse);
                message.Body = model.Besked;
                SmtpClient client = new SmtpClient("127.0.0.1", 25);
                client.Send(message);
            }
        }
    }
    

    My kontakt Model code

    using System.ComponentModel.DataAnnotations;
    
    namespace InstallUmbraco.Models
    {
        public class KontaktModel
        {
            [Required]
            [Display(Name = "Fornavn:")]
            public string Fornavn { get; set; }
    
            [Required]
            [Display(Name = "Efternavn:")]
            public string Efternavn { get; set; }
    
            [Required]
            [EmailAddress]
            [Display(Name = "Email Addresse:")]
            public string EmailAddresse { get; set; }
    
            [Required]
            [Display(Name = "Besked:")]
            public string Besked { get; set; }
        }
    }
    

    That is all my code for the contact form :D i am not sure where it goes wrong and why?

Please Sign in or register to post replies

Write your reply to:

Draft