c# - 'Global' variables Razor -
i'm creating form members of site can change passwords accounts, , i'd display message explaining mistakes users made while filling fields (such password short, needs @ least non-alphanumeric character, etc.). i'd display these messages in same page, beside field names. here's code:
@helper renderform() { <form method="post"> <p>change password below</p> <div><label for="currentpassword">current password</label> <input type="password" id="currentpassword" name="currentpassword"/></div> <div><label for="newpassword">new password:</label> <input type="password" id="newpassword" name="newpassword"/></div> <div><label for="confirmpassword">confirm new password</label> <input type="password" id="confirmpassword" name="confirmpassword"/></div> <div><input type="submit" id="submit" name="submit" value="submit"/></div> </form> } @helper message(string message) { <p>@message</p> } <style type="text/css"> p,label {color:black;} </style> @{ if(!ispost) { @renderform(); } else { var account = membership.getuser(); var currentpassword = httpcontext.current.request["currentpassword"]; if(membership.validateuser(account.username, currentpassword)){ var newpassword = httpcontext.current.request["newpassword"]; var confirmpassword = httpcontext.current.request["currentpassword"]; if(check(newpassword, confirmpassword)){ account.changepassword(account.resetpassword(), newpassword); } } else { @message("the password provided didn't match database."); } } } @functions{ list<string> check(string newpassword, string confirmpassword) { //just place holder return false; } }
i've tried adding list filled when error found, , when form reloaded message displayed, renderform() function can't find reference list. how can display these messages?
you should use built in validation comes web pages framework. have article explains how use it: http://www.mikesdotnetting.com/article/191/validation-in-razor-web-pages-2
Comments
Post a Comment