Copied to clipboard

Flag this post as spam?

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


  • Ayo Adesina 445 posts 1059 karma points
    May 29, 2014 @ 01:12
    Ayo Adesina
    0

    Processing the result for a Surface Controller

    public class ContactController : SurfaceController 
    {
        [HttpPost]
        public JsonResult SendMail(Contact model)
        {
            if (ModelState.IsValid)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("<p>Name:{0}</p>", model.YourName);
                sb.AppendFormat("<p>Email:{0}</p>", model.Email);
    
                sb.AppendFormat("<p>Message:{0}</p>", model.Message);
    
                library.SendMail(model.Email, "[email protected]", model.Subject,                sb.ToString(), true);
                return Json(true);
    
            }
            return Json(false);
        }
    }
    

    I have this surface controller and it is doing exactly what I want BUT my problem is two fold:

    1. All of a sudden when I click submit on my form it will not post to the controller instead the browser is throwing a JS error > Uncaught ReferenceError: Sys is not defined

    This is the form

    @using (Ajax.BeginForm("SendMail", "Contact", new AjaxOptions
    {
       HttpMethod = "POST",
       OnFailure = "ShowError()",
       OnSuccess = "ShowSuccess()"
    }))
    {
    
    @Html.ValidationMessageFor(model => model.YourName)
    @Html.ValidationMessageFor(model => model.Email)
    @Html.ValidationMessageFor(model => model.Subject)
    @Html.ValidationMessageFor(model => model.Message)
    
    
    
    @Html.ValidationSummary(true, "Errors")
    
    @Html.EditorFor(model => model.YourName)
    
    
    @Html.EditorFor(model => model.Email)
    
    
    @Html.EditorFor(model => model.Subject)
    
    
    @Html.TextAreaFor(model => model.Message)
    
    <input type="submit" id="submit-mail" class="submit-btn rounded" value="SEND MESSAGE" />
    

    Uncaught ReferenceError: Sys is not defined

    2.How can I process the result of the controller, as you can see I am trying to use JSON but all that happens (when it was working and posting to the controller) the browser just shows the string True/False instead of running the js functions.

    Any Ideas?

Please Sign in or register to post replies

Write your reply to:

Draft