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

  • SEARCH
  • Home
  • 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 8223033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:31:46+00:00 2026-06-07T14:31:46+00:00

hi guys sorry i m really new to mvc3 javascript jquery etc. i have

  • 0

hi guys sorry i m really new to mvc3 javascript jquery etc.
i have an internal server error 500

this is the controller:

    [HttpGet]
    public JsonResult GetEmail(string title, string notes) 
    {
        byte[] pdf = null;
        byte[] excel = null;
        string userEmail = "";
        try
        {
            pdf = GetFileForMail("PDF", "ServiceArea_" + System.DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".pdf", title, notes);
            excel = GetFileForMail("EXCEL", "ServiceArea_" + System.DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xls", title, notes);



            MembershipUser mu = Membership.GetUser(this.MembershipData.Principal.Identity.Name);
            userEmail = mu.Email.ToString();


            System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage(userEmail,
                                                                        "mailexample@mail.com",
                                                                        title,
                                                                        notes);
            mailMsg.To.Add("no-replay@valuelab.it");
            mailMsg.IsBodyHtml = true;

            string mese = "";
            string giorno = "";
            string ore = "";

            if (DateTime.Now.Month < 10)
                mese = "0" + DateTime.Now.Month;
            else
                mese = "" + DateTime.Now.Month;

            if (DateTime.Now.Day < 10)
                giorno = "0" + DateTime.Now.Day;
            else
                giorno = "" + DateTime.Now.Day;

            if(DateTime.Now.Hour < 10)
                ore = "0" + DateTime.Now.Hour;
            else
                ore = "" + DateTime.Now.Hour;

            System.Net.Mail.Attachment att = new System.Net.Mail.Attachment(new MemoryStream(pdf), DateTime.Now.Year + mese  + giorno + "_" + ore + DateTime.Now.Minute + " Report.pdf", System.Net.Mime.MediaTypeNames.Application.Pdf);

            System.Net.Mail.Attachment att2 = new System.Net.Mail.Attachment(new MemoryStream(excel), DateTime.Now.Year + mese + giorno + "_" + ore + DateTime.Now.Minute + " Report.xls", "application/vnd.ms-excel");

            mailMsg.Attachments.Add(att);
            mailMsg.Attachments.Add(att2);
            System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient();
            sc.Host = "192.168.99.1";
            sc.Send(mailMsg);
            return Json(new { text = "Everything is fine " + userEmail, risultato = true });
        }
        catch (Exception e) {
            return Json(new { text = "Unexpected error" + userEmail , risultato = false});
        }


    }

and this is the way in which i call the controller:

   jQuery.ajax({
                type: "GET",
                url: options.EmailUrl,
                dataType: "json",
                data:
                {
                    title: viewModel.saReportTitle(),
                    notes: viewModel.saReportNotes()
                },
                success: function (data, textStatus, jqXHR) {
                    jQuery("#sa-dialog-alert").dialog('open');
                    jQuery("#sa-dialog-alert").dialog('option', 'title', 'Invio Mail Eseguito');
                    jQuery("#sa-dialog-alert").text(data.text);
                }
                ,
                error: function (data, textStatus, errorThrown) {
                    jQuery("#sa-dialog-alert").dialog('open');
                    jQuery("#sa-dialog-alert").dialog('option', 'title', 'Errore');
                    jQuery("#sa-dialog-alert").text("Errore nell'invio mail: " + errorThrown);
                }
            });

If you read the code the controller just send an email
and IT WORK FINE THERE are no exception
so why ajax say there is a 500 internal server error?

  • 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-06-07T14:31:47+00:00Added an answer on June 7, 2026 at 2:31 pm

    By default GET requests are not allowed on JsonResult so you need to excplicitly allow them, with setting the JsonRequestBehavior property:

    return Json(
        new { text = "Everything is fine " + userEmail, risultato = true },
        JsonRequestBehavior.AllowGet
    );
    

    Or use POST as your request method in your AJAX call.

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

Sidebar

Related Questions

Sorry guys, didn't know how to word this one. Still learning jquery and have
Ok guys, I'm really new at python (and programming itself) so sorry for my
Sorry guys, not being lazy, I know others have had the same error message
Sorry for this guys, but I really am unlucky today. Please help, my problem
Sorry guys for the really simple question but I have tried to float one
I'm really a beginner in R so, sorry if my code shocks you guys.
Hello guys sorry if the question looks stupid to you. i have 3 tables
Sorry guys, I posted this earlier today where my add as linked images were
really new to JQuery.. like 2 hours new. Began to write a drop down
Good day. I never really got a good hand at JavaScript, therefore this unusual

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.