Copied to clipboard

Flag this post as spam?

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


  • Jonas Gunnarsson 44 posts 194 karma points
    Apr 08, 2014 @ 13:08
    Jonas Gunnarsson
    0

    Contact form - namespace name 'Models' does not exist

    Hi, I´m new to MVC, and I have followed a tutorial for building a contact form page but get this error message: namespace name 'Models' does not exist

    Gets a lot of code, but I do not know what is relevant and not.

    Controller

    namespace test.Controllers {
        public class ContactSurfaceController : SurfaceController
    
        {
            [HttpPost]
            public ActionResult Contact(ContactModel model)
            {
                if (ModelState.IsValid)
                {
                    var sb = new StringBuilder();
                    sb.AppendFormat("<p>Meddelande: {0}</p>", model.Message);
                    sb.AppendFormat("<p>Namn: {0}</p>", model.Name);
                    sb.AppendFormat("<p>E-post: {0}</p>", model.Email);
                    sb.AppendFormat("<p>Telefon: {0}</p>", model.Phone);
    
                    library.SendMail("[email protected]", "[email protected]", model.Subject, sb.ToString(), true);
    
                    return RedirectToUmbracoPage(model.ThankYouPage);
                }
                return CurrentUmbracoPage();
            }
    
    
        } }
    

    Model

    namespace test.Models
    {
        public class ContactModel
        {
            [Required]
            [DisplayName("Ärende")]
            public string Subject { get; set; }
            [Required]
            [DisplayName("Namn")]
            public string Name { get; set; }
            [Required]
            [DisplayName("E-post")]
            public string Email { get; set; }
            [DisplayName("Telefon")]
            public string Phone { get; set; }
            [Required]
            [DisplayName("Ärende")]
            public string Message { get; set; }
            public int ThankYouPage { get; set; }
        }
    }
    

    Partial View

    @model test.Models.ContactModel
    
    @using (Html.BeginUmbracoForm("Contact", "ContactSurface", null, new {@class = "contact-form" }))
    { 
        @Html.ValidationSummary(true)
    
        <div>
    
            @Html.LabelFor(x => x.Subject)
            @Html.TextBoxFor(x => x.Subject)
            @Html.ValidationMessageFor(x => x.Subject)
    
            @Html.LabelFor(x => x.Message)
            @Html.TextAreaFor(x => x.Message)
            @Html.ValidationMessageFor(x => x.Message)
    
            @Html.LabelFor(x => x.Name)
            @Html.TextBoxFor(x => x.Name)
            @Html.ValidationMessageFor(x => x.Name)
    
            @Html.LabelFor(x => x.Phone)
            @Html.TextBoxFor(x => x.Phone)
            @Html.ValidationMessageFor(x => x.Phone)
    
            @Html.LabelFor(x => x.Email)
            @Html.TextBoxFor(x => x.Email)
            @Html.ValidationMessageFor(x => x.Email)
    
            @Html.HiddenFor(x => x.ThankYouPage)
    
        </div>
        <input type="submit" value="Skicka" class="btn-accept" />
    }
    

    And it´s here I get the error message on the first line

    @using test.Models
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        Layout = "uBlogsyBaseSite.cshtml";
    }
    
    @Html.Partial("ContactForm", new ContactModel { ThankYouPage = Model.Content.GetPropertyValue<int>("thankYouPage") })
    

    What have I missed?

    EDIT: Sry, I´m using Umbraco 7.0.3 and .net 4.5.

    Thanks, Jonas

  • Jonas Gunnarsson 44 posts 194 karma points
    Apr 09, 2014 @ 11:04
    Jonas Gunnarsson
    0

    I really need help with this, any help is appreciated.

  • Jonas Gunnarsson 44 posts 194 karma points
    Apr 10, 2014 @ 11:40
    Jonas Gunnarsson
    100

    I got it work, it was because surface controller code and model code not was in the app_code folder.

    But I have another question. How do I make this as an macro? I put my contact.cshtml in the MacroPartials folder and made a new macro with that view. But it dosen´t work, I get this error:

    Error loading Partial View script (file: ~/Views/MacroPartials/ContactForm.cshtml)

    Any suggestions?

  • Peter 8 posts 88 karma points
    Sep 25, 2020 @ 05:06
    Peter
    0

    Hi Jonas Gunnarsson

    What is solutions for this, I got the same problem when I updated to Umbraco 8.8:

    https://our.umbraco.com/forum/using-umbraco-and-getting-started//103625-umbracoformsformpicker-contactforms-errors-in-umbraco-88-rc

    Peter

Please Sign in or register to post replies

Write your reply to:

Draft