Copied to clipboard

Flag this post as spam?

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


  • Krum 12 posts 83 karma points notactivated
    Jun 23, 2016 @ 13:40
    Krum
    0

    Ajax form error

    Hi, in my master template I have a Ajax.BeginForm, but on submit i get

    There is not current PublishedContentRequest, it must be initialized before the RenderRouteHandler executes
    

    Any ideas what could be causing this?

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Jun 23, 2016 @ 13:56
    Michaël Vanbrabandt
    0

    Hi Krum,

    you will have to give more details about this.

    Can you post the full code of your form including controller and model?

    I think you are creating a surface controller without the surface prefix. But for that I need to see more code.

    /Michaël

  • Ostap-Svyatoslav 1 post 71 karma points
    Aug 18, 2019 @ 12:39
    Ostap-Svyatoslav
    0

    Hi Michaël Vanbrabandt, I have the same problem. And it is kinda weird.

    So I have Surface Controller for log in log out the registration and forgot password requests. When I using Ajax.BeginForm without RenderRouteHandler in arguments it will give me an error. But when I typed there some random classes there like

    "new { email = new EmailSender()}"

    it will act okay, but after the request, it will send me to the blank page wich have the url of request and RenderRouteHandler value.

    Also when i do the same request with RenderRouteHandler arguments while member logged in, it acts like normal ajax request.

    Code of Controler:

    enter using System.Web.Mvc;
    using System.Web.Security;
    using Umbraco.Web.Mvc;
    using REDAirCalculator.Models.DTO;
    using MailKit.Net.Smtp;
    using MimeKit;
    using REDAirCalculator.Models;
    using System.IO;
    using REDAirCalculator.DAL;
    
    namespace REDAirCalculator.Controllers
    {
         public class MembersController : SurfaceController
         {
              private readonly IProjectRepository _projectRepository;
    
        public MembersController(IProjectRepository projectRepository)
        {
            _projectRepository = projectRepository;
        }
    
        [HttpPost]
        public void PasswordRecovery(Email userEmail)
        {
            MimeMessage message = new MimeMessage();
    
            MailboxAddress from = new MailboxAddress("User",
            "[email protected]");
            message.From.Add(from);
    
            MailboxAddress to = new MailboxAddress("User",
            userEmail.EmailAddress);
            message.To.Add(to);
    
            message.Subject = "Password recovery";
    
            BodyBuilder bodyBuilder = new BodyBuilder();
    
            string msg = Request.Url.ToString().Replace("PasswordRecovery?emailUser=Umbraco.Core.EmailSender",
                "ForgetPassword?memberGuId=" + Umbraco.MembershipHelper.GetByEmail(userEmail.EmailAddress).Id.ToString());
    
            bodyBuilder.TextBody = msg;
    
            message.Body = bodyBuilder.ToMessageBody();
    
            SmtpClient client = new SmtpClient();
            client.Connect("smtp.gmail.com", 465, true);
            client.Authenticate("emailaddress", "password");
    
            client.Send(message);
            client.Disconnect(true);
            client.Dispose();
        }
    }
    

    View code:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<REDAirCalculator.Models.DTO.Email>
    @using Umbraco.Web
    @{
          string popupCancelText = Umbraco.GetDictionaryValue("Popup cancel text");
    
    string emailPopupTitleText = Umbraco.GetDictionaryValue("Email popup title text");
    string emailPopupAddressText = Umbraco.GetDictionaryValue("Email popup address text");
    string emailPopupOkText = Umbraco.GetDictionaryValue("Email popup ok text");
    
    var currentEntryObjectGuid = TempData["Forms_Current_Record_id"];
    }
    
    
    
    <script src="~/node_modules/jquery-ajax-unobtrusive/dist/jquery.unobtrusive-ajax.min.js"></script>
    
    
    
    @using (Ajax.BeginForm("PasswordRecovery", "Members", new AjaxOptions { OnSuccess = "onSuccess", OnFailure = "onFail", OnBegin = "onBegin" }, new { @class = "project-form" }))
    {
    
    <button type="button" class="project-close-btn close btn btn-lg disabled" data-dismiss="modal" aria-label="Close">
        ✕
    </button>
    
    <h3 class="modal-title project-title" id="emailProjectTitle">@emailPopupTitleText</h3>
    
    <div class="form-group project-input-container">
        <label for="EmailAddress" class="bmd-label-floating">@emailPopupAddressText</label>
        <input required class="form-control" id="EmailAddress" name="EmailAddress" data-val="true" data-val-required="The Email field is required."
               data-val-regex="Please enter a valid e-mail address" type="email" value=""
               data-val-regex-pattern="[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?">
        <span class="field-validation-valid bmd-help" data-valmsg-for="EmailAddress" data-valmsg-replace="true"></span>
    </div>
    
    <div class="project-btn-container">
        <input name="mail" type="submit" class="btn btn-primary project-submit-btn project-email-btn" value="Recover" />
    </div>
    }
    
  • Tarik 196 posts 840 karma points c-trib
    Aug 19, 2019 @ 12:03
    Tarik
    0

    Did you enable client validation?

    Did you import required libraries?

    @{
        Html.EnableClientValidation();
        Html.EnableUnobtrusiveJavaScript();
    }
    

    JS libraries:

    <script src="https://code.jquery.com/jquery-3.1.1.min.js"
            integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
            crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.1/jquery.validate.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.unobtrusive-ajax.min.js"
            integrity="sha256-PAC000yuHt78nszJ2RO0OiDMu/uLzPLRlYTk8J3AO10="
            crossorigin="anonymous"></script>
    
Please Sign in or register to post replies

Write your reply to:

Draft