Copied to clipboard

Flag this post as spam?

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


  • Mike Beale 38 posts 132 karma points
    Jul 13, 2018 @ 09:29
    Mike Beale
    0

    Many partial view errors in Visual Studio

    Hi,

    I'm trying to create a simple contact form for a site by following the instructions here https://codeshare.co.uk/blog/how-to-create-a-contact-form-in-umbraco-using-mvc-and-c/

    All goes fine until I create the contact.cshtml partial view and Visual Studio throws up lots of errors, most of them are the same.

    Screen shot of Visual Studio

    Here is the model ContactModel.cs :

    using System.ComponentModel.DataAnnotations;
    
    namespace HappyFrog.Models
    {
        public class ContactModel
        {
            [Required]
            [Display(Name = "Name:")]
            public string Name { get; set; }
    
            [Required]
            [EmailAddress]
            [Display(Name = "Email Address:")]
            public string EmailAddress { get; set; }
    
            [Required]
            [Display(Name = "Message:")]
            public string Message { get; set; }
        }
    }
    

    Here is the controller ContactSurfaceController.cs

    using Umbraco.Web.Mvc;
    using System.Web.Mvc;
    using HappyFrog.Models;
    using System.Net.Mail;
    
    namespace HappyFrog.Controllers
    {
        public class ContactSurfaceController : SurfaceController
        {
            public const string PARTIAL_VIEW_FOLDER = "~/Views/Partials/Contact/";
    
            public ActionResult RenderForm()
            {
                return PartialView(PARTIAL_VIEW_FOLDER + "Contact.cshtml");
            }
    
            [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult SubmitForm(ContactModel model)
            {
                if (ModelState.IsValid)
                {
                    SendEmail(model);
                    TempData["ContactSuccess"] = true;
                    return RedirectToCurrentUmbracoPage();
                }
                return CurrentUmbracoPage();
            }
    
            private void SendEmail(ContactModel model)
            {
                MailMessage message = new MailMessage(model.EmailAddress, "[email protected]")
                {
                    Subject = "Enquiry from" + model.Name,
                    Body = "Name: " + model.Name + "\r\n\r\n" +
                    "Email address: " + model.EmailAddress + "\r\n\r\n" +
                    "Message:\r\n" + model.Message
                };
    
                SmtpClient client = new SmtpClient()
                {
                    Host = "auth.smtp.1and1.co.uk",
                    Port = 587,
                    EnableSsl = true,
                    Credentials = new System.Net.NetworkCredential("[email protected]", "password")
                };
                client.Send(message);
            }
        }
    }
    

    And the code in Contact.cshtml in the View\Partials\Contact folder:

    @inherits UmbracoViewPage<HappyFrog.Models.ContactModel>
    
    @using (Html.BeginUmbracoForm("SubmitForm", "ContactSurface", FormMethod.Post))
    {
        @Html.AntiForgeryToken()
    
        <div class="form-group">
            @Html.ValidationSummary()
        </div>
    
        <div class="form-group">
            <div class="col-xs-3">
                @Html.LabelFor(m => m.Name)
            </div>
            <div class="col-xs-9">
                @Html.TextBoxFor(m => m.Name)
            </div>
        </div>
    
        <div class="form-group">
            <div class="col-xs-3">
                @Html.LabelFor(m => m.EmailAddress)
            </div>
            <div class="col-xs-9">
                @Html.TextBoxFor(m => m.EmailAddress)
            </div>
        </div>
    
        <div class="form-group">
            <div class="col-xs-3">
                @Html.LabelFor(m => m.Message)
            </div>
            <div class="col-xs-9">
                @Html.TextAreaFor(m => m.Message)
            </div>
        </div>
        <button>Submit</button>
    }
    

    And finally the errors in Visual Studio:

    Error   CS0115  '_Page_Views_Partials_Contact_Contact_cshtml.Execute()': no suitable method found to override   Contact.cshtml  Line 1
    Error   CS0246  The type or namespace name 'UmbracoViewPage<>' could not be found (are you missing a using directive or an assembly reference?) Contact.cshtml  Line 1
    Error   CS0103  The name 'Context' does not exist in the current context    Contact.cshtml  Line 1
    Error   CS0246  The type or namespace name 'UmbracoViewPage<>' could not be found (are you missing a using directive or an assembly reference?) Contact.cshtml  Line 1
    Error   CS0103  The name 'Html' does not exist in the current context   Contact.cshtml  Line 3
    Error   CS0103  The name 'FormMethod' does not exist in the current context Contact.cshtml  Line 3
    Error   CS0103  The name 'Html' does not exist in the current context   Contact.cshtml  Line 5
    Error   CS0103  The name 'Html' does not exist in the current context   Contact.cshtml  Line 8
    Error   CS0103  The name 'Html' does not exist in the current context   Contact.cshtml  Line 13
    Error   CS0103  The name 'Html' does not exist in the current context   Contact.cshtml  Line 16
    Error   CS0103  The name 'Html' does not exist in the current context   Contact.cshtml  Line 22
    Error   CS0103  The name 'Html' does not exist in the current context   Contact.cshtml  Line 25
    Error   CS0103  The name 'Html' does not exist in the current context   Contact.cshtml  Line 31
    Error   CS0103  The name 'Html' does not exist in the current context   Contact.cshtml  Line 34
    Warning AD0001  Analyzer 'Microsoft.CodeAnalysis.CSharp.Analyzers.FixAnalyzers.CSharpFixerWithFixAllAnalyzer' threw an exception of type 'System.TypeInitializationException' with message 'The type initializer for 'Microsoft.CodeAnalysis.Analyzers.FixAnalyzers.FixerWithFixAllAnalyzer`1' threw an exception.'.    CSC 1
    

    All the errors are in the Contact.cshtml partial view

    • Site is using Umbraco 7.10.4
    • Visual Studio 2017
    • I installed Umbraco 7.10.4 into Visual Studio via Nuget into an empty project.
    • I didn't use the starter kit Paul mentions in his video as the site

    I hope I'm missing something simple.

  • Mike Beale 38 posts 132 karma points
    Jul 13, 2018 @ 09:52
    Mike Beale
    0

    I've just ran the site locally in Visual Studio and completed the Umbraco setup.

    I no longer get any errors, but am getting the following warning 19 times in the Contact.cshtml

    Warning CS1702  Assuming assembly reference 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' used by 'umbraco' matches identity 'System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' of 'System.Web.Mvc', you may need to supply runtime policy
    

    So something still not quite right?

  • ibrahim TUNC 54 posts 132 karma points
    Feb 11, 2019 @ 13:26
    ibrahim TUNC
    0

    After installation of Umraco with MVC selection

    1- If the following lines of code give a warning:        Assuming assembly reference 'system.web.mvc version = 5.2.3.0 culture = neutral, publickeytoken = version = 5.2.4.0

       Requirements:

       If the Microsoft.AspNet.Mvc package is version 5.2.4 or higher    Remove the installed package from the Nuget Package Manager by selecting the dependency options,    Then, installing Install.Package Microsoft.AspNet.Mvc -Version 5.2.3 will eliminate the problem.

    2- After doing this step, you will need to Clean Solution and then Build it. 3- In the build process, it can give an error message as follows.

       Analyzer 'Microsoft.CodeAnalysis.CSharp.Analyzers.FixAnalyzers.CSharpFixerWithFixAllAnalyzer' threw an exception of type    Solution from Console    From the following URL    https://www.nuget.org/packages/microsoft.codeanalysis.analyzers

       Microsoft.CodeAnalysis.Analyzers 2.6.3 The Nuget Package will be installed to correct the corresponding error.

       Then you will need to Clean the project and then Clean again.

Please Sign in or register to post replies

Write your reply to:

Draft