문제

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
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top