简体   繁体   中英

Compare input value to string in IF statement C# ASP.NET Razor

So i'm trying to adjust a small piece of code (i'm not known with C# ASP.NET Razor) to where i can compare an user value input to my own string like so:

<input id="test" name="test" type="text" value="hello" required>

string strTest = Library.StripHtml(Request["test"]).ToString();

if(string.IsNullOrEmpty(strTest)){
            client.Send(mail);
        }

to something like

if(test.input == "hello"){
                client.Send(mail);
            }

The idea behind it is to make the field required so that if the value is changed the mail wont send (honeypot method). I guess most bots simply don't fill the forms without an requirement.

Your question lacks some information or code. The input has an id test but the condition is using strTest so there is some other code involved in parsing the input.

Assuming that you can still use the strTest variable in your new condition, why not simply check that variable against your predefined string?

if(strTest == "hello"){
                client.Send(mail);
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM