my script is bellow
$(function () {
$(".formSubmit").click(function () {
var cName = $('#cName').val();
var cSurname = $('#cSurname').val();
var cEmail = $('#cEmail').val();
var cMessage = $('#cMessage').val();
console.log(cMessage);
console.log(cEmail);
console.log(cSurname);
console.log(cName);
if (cName != null && cName != '' && cSurname != null && cSurname != '' && cEmail != null && cEmail != '' && cMessage != null && cMessage != '') {
$.ajax({
type: "GET",
url: "/api/contactusapi/" + cName + "/" + cSurname + "/" + cEmail + "/" + cMessage + "/?",
contentType: "json",
dataType: "json",
success: function (data) {
if (data != null) {
}
},
error: function (xhr) {
alert(xhr.responseText);
}
});
}
});
});
And my "contactusapi" api is below
namespace iskorumacom.Controllers
{
public class ContactUsApiController : ApiController
{
[HttpGet]
public int Get(string cName, string cSurname, string cEmail, string cMessage)
{
try
{
using (Data.DataClassesDataContext dc = new Data.DataClassesDataContext())
{
string cHTML =
"<h3></h3>" +
"<b>Ad:</b> " + cName + "<br />" +
"<b>Soyad :</b> " + cSurname + "<br />" +
"<b>e-Mail :</b> " + cEmail + "<br />" +
"<b>Mesaj :</b> " + cMessage;
using (MailMessage MailMessageLocal = new MailMessage())
{
MailMessageLocal.From =
new MailAddress("m@majorworx.com", cName + " " + cSurname, System.Text.Encoding.UTF8);
MailMessageLocal.To.Add("m@majorworx.com");
MailMessageLocal.Subject = "İletişim Formu Formu";
MailMessageLocal.IsBodyHtml = true;
MailMessageLocal.BodyEncoding = System.Text.Encoding.UTF8;
MailMessageLocal.Body = cHTML;
MailMessageLocal.Priority = MailPriority.High;
using (SmtpClient SmtpClientLocal = new SmtpClient())
{
return -1;
}
}
}
}
catch
{
return 0;
}
}
}
}
and my route.config folder
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "iskorumacom.Controllers" }
);
}