Check it against null
like:
if(Request["customerName"] != null)
{
//Post key exists
}
题
I am new to c# and making simple contact form, for now i got this in view
@{
var customerName = Request["customerName"];
var customerEmail = Request["customerEmail"];
var customerRequest = Request["customerRequest"];
var errorMessage = "";
var debuggingFlag = false;
try {
// Initialize WebMail helper
WebMail.SmtpServer = "your-SMTP-host";
WebMail.SmtpPort = 25;
WebMail.UserName = "your-user-name-here";
WebMail.Password = "your-account-password";
WebMail.From = "your-email-address-here";
// Send email
WebMail.Send(to: customerEmail,
subject: "Help request from - " + customerName,
body: customerRequest
);
}
catch (Exception ex ) {
errorMessage = ex.Message;
}
}
It is ok for now, but how to check in POST varibales exist i know in PHP
if (isset($_POST["customerName"]) && !empty($_POST["customerName"])) {
}
very easy, but how to do that in C#
解决方案
Check it against null
like:
if(Request["customerName"] != null)
{
//Post key exists
}