Guest User

Guest User

  • Tech Writer
  • 611
  • 117.5k

Null Value face error in mvc.

Sep 12 2020 5:08 AM
It's me email send code in mvc but i have face issue .I have enter toEmail in textbox and body but here null value face issue) 
public IActionResult SendEmail(string toEmail, string ToName, string from, string FromName, string Subject, string body)
{
try
{
string admin_email = "****";
string admin_emailpwd = "*****";
MailMessage mail = new MailMessage();
mail.To.Add(toEmail);
mail.From = new MailAddress(admin_email);
mail.Subject = Subject;
mail.Body = body;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.Normal;
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.smtp2go.com";
smtp.Port = 2525;
smtp.UseDefaultCredentials = true;
smtp.Credentials = new System.Net.NetworkCredential(admin_email, admin_emailpwd);
smtp.EnableSsl = true;
smtp.Send(mail);
 
it's me html and jquery code .Jquery code get textbox value jquery code working fine.
 
<div class="modal fade" id="add-reply" tabindex="-1" role="dialog" aria-labelledby="add-reply">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title has-icon ms-icon-round">Answer to the Query</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
<form action="/action_page.php">
<div class="ms-form-group has-icon">
@*<textarea rows="1" class="form-control" placeholder="Email"></textarea>*@
<textarea rows="1" tex class="form-control" placeholder="Email" id="txtTo"></textarea>
</div>
<div class="ms-form-group has-icon">
<textarea rows="4" class="form-control" placeholder="Enter your text here" id="txtBody"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-info shadow-none" id="btnSend">Submit</button>
</div>
</div>
</div>
</div>
 
$("#btnSend").click(function () {
debugger;
console.log("click");
var toEmail = $.trim($("#txtTo").val());
//var subject = $.trim($("[id*=txtSubject]").val());
var body = $.trim($("[id*=txtBody]").val());
$.ajax({
type: "POST",
url: "SendEmail",
data: "{ toEmail: '" + toEmail + "', body: '" + body + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
alert(r.d);
},
error: function (r) {
alert(r.responseText);
},
failure: function (r) {
alert(r.responseText);
}
});
return false;
});
});
Please check this 

Answers (7)