Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4021312
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:20:10+00:00 2026-05-20T10:20:10+00:00

I am trying to call a controller via ajax without to much luck. I

  • 0

I am trying to call a controller via ajax without to much luck.
I have create this in my view

    <input type="submit" id="preview-email" value="Preview Email" />

   <script type="text/javascript">
    $("#preview-email").click(function () {
        var p = { "email": "1223" };
        $.ajax({
            url: '/BusinessController/PreviewEmail',
            type: "POST",
            data: p,
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                alert(data);
            },
            error: function () {
                alert("error");
            }
        });
    });


</script>

My controller

 [HttpPost]
    public ActionResult PreviewEmail(string email)
    {
      //  string d = ViewData["editor"].ToString();
        string e = System.Web.HttpUtility.HtmlDecode(email);
        EmailModel model = new EmailModel() { EmailBody = e };
        return PartialView("_PreviewEmail", model);
    }

Turning on fiddler is telling me that its a 500 error. What have I done wrong? I’ve placed a breakpoint on my controller however it doesnt get that far

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:20:11+00:00Added an answer on May 20, 2026 at 10:20 am

    Your URL should be:

    ‘/Business/PreviewEmail’

    instead of:

    ‘/BusinessController/PreviewEmail’

    However, the recommended practice for building URLs is to use your routes:

    Url.Action(“PreviewEmail”, “Business”)

    BTW, you have another problem in your code. By setting “application/json” as your contentType, MVC will expect a JSON string. However, when you assign a JavaScript object to the data property of $.ajax(), jQuery will serialize the value to this:

    email=1223

    So you’ll want to assign a string to the data property instead by doing this:

    var p = ‘{ “email”: “1223” }’;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a call to a controller via jQuery $.post, but the
I'm trying to implement a view controller for a custom NSOpenGLView based view (this
I am trying to create a two view, single controller application as follows: I
I'm trying to send some data via JQuery ajax to a grails controller Here's
I have a troubleshoot with my MVC project. I'm trying to do this: On
Trying to integrate some friendly_id gem functionality on a controller method. Essentially, I have
I'm trying to open the email view controller ( MFMailComposeViewController ), and everything I
I'm trying to call a controller method from a javascript function, I read that
Trying to have a AJAX action link which when clicked, should do a HttpGet
I created a web application in ASP.NET MVC and trying to call a controller

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.