Copied to clipboard

Flag this post as spam?

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


  • Miguel P 1 post 21 karma points
    Mar 19, 2015 @ 14:33
    Miguel P
    0

    "Error loading Partial View script" while "return CurrentUmbracoPage()"

    Hello People,

    I´m a beginner at Umbraco, so right now I´m trying to create a simple Contact form, which I is almost complete, except by the validation data which I can´t return without the error:

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

     

    I´ve been reading a lot about this thread, but still not sure what the problem is.

    This is the code that I got:

     

    MacroPartials/ContactForm.cshtml

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @Html.Action("ContactUsForm", "Contact")

     

    Partials/ContactUsForm.cshtml

    @model StoreMVC.Models.ContactModel

    @using (Html.BeginUmbracoForm("ContactUsForm", "Contact"))
    {
    @Html.ValidationSummary(true)

    Contact Us








    @Html.ValidationSummary(true)




    @Html.LabelFor(x => x.Name)
    @Html.TextBoxFor(x => x.Name)
    @Html.ValidationMessageFor(x => x.Name)




    @Html.LabelFor(x => x.Email)
    @Html.TextBoxFor(x => x.Email)
    @Html.ValidationMessageFor(x => x.Email)




    @Html.LabelFor(x => x.Phone)
    @Html.TextBoxFor(x => x.Phone)
    @Html.ValidationMessageFor(x => x.Phone)





    @Html.LabelFor(x => x.Message)
    @Html.TextAreaFor(x => x.Message)
    @Html.ValidationMessageFor(x => x.Message)




    }

     

    Controllers/ContactController.cs

    using StoreMVC.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Umbraco.Web;

    namespace StoreMVC.Controllers
    {
    public class ContactController : Umbraco.Web.Mvc.SurfaceController
    {
    [ChildActionOnly]
    public ActionResult ContactUsForm()
    {
    var model = new ContactModel();


    //In case you need to access the current node
    var currentNode = Umbraco.TypedContent(UmbracoContext.PageId.GetValueOrDefault());


    return PartialView("ContactUsForm", model);
    }


    [HttpPost]
    public ActionResult ContactUsForm(ContactModel model)
    {
    // server validation here
    TempData["ErrorMessage"] = "Error processing field ...";

    if (ModelState.IsValid)
    {
    var currentNode = Umbraco.TypedContent(UmbracoContext.PageId.GetValueOrDefault());

    var homeNode = currentNode;

    var sendEmailsFrom = homeNode.GetPropertyValue("sendEmailsFrom") ?? model.Email;
    var sendEmailsTo = homeNode.GetPropertyValue("sendEmailsTo") ?? "[email protected]";

    var body = String.Format("From: {0},

    Email: {1},

    Tel: {2},

    Message: {3}", model.Name, model.Email, model.Phone, model.Message);
    var subject = "StoreMVC - Contact";


    try
    {
    umbraco.library.SendMail(sendEmailsFrom, sendEmailsTo, subject, body, true);

    TempData["InfoMessage"] = "Your message has been successfully sent and we will be in touch soon...";

    // Clear all the form fields
    ModelState.Clear();
    model.Name = string.Empty;
    model.Phone = string.Empty;
    model.Email = string.Empty;
    model.Message = string.Empty;


    //redirect to current page to clear the form
    return RedirectToCurrentUmbracoPage();
    }
    catch (Exception ex)
    {
    TempData["ErrorMessage"] = ex.Message + ex.StackTrace;
    }
    }


    return CurrentUmbracoPage();

    }
    }
    }

     

    Models/ContactModel.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web;

    namespace StoreMVC.Models
    {
    public class ContactModel
    {
    [Required(ErrorMessage = "Name is required")]
    public string Name { get; set; }

    [Required]
    public string Email { get; set; }

    [Required]
    public string Phone { get; set; }

    [Required]
    public string Message { get; set; }
    }
    }

     

    Any help, would be really appreciated!

    Regards


  • Umbraker 4 posts 74 karma points
    Feb 09, 2016 @ 20:54
    Umbraker
    0

    Hi, i have the same issue, if you know how to fix it, please let me know! kind regards

  • Daniel 60 posts 174 karma points
    Feb 09, 2016 @ 20:56
    Daniel
    0

    Pure guess:

    return PartialView("ContactUsForm", model);
    

    It may not be able to find this view, try putting in the full path

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies