文本框中的值如何在 c# mvc 中是字符串或数字

我有用户名和密码文本框,我想检查用户何时输入任何登录名,登录名是字符串还是数字。如果登录名是字符串,则此函数调用其他函数调用。


**Login Function**




 public DataTable mlogin(string username, string password)

                {

                    string constring = ConfigurationManager.ConnectionStrings["Real"].ConnectionString;


                        using (SqlConnection con = new SqlConnection(constring))

                        {

                            password = Cryptographer.Encrypt(password);


                            con.Open();

                            using (SqlCommand cmd = new SqlCommand("select MD.MembershipID, MembershipName, address, ISNULL(FD.FileID,'') as FileID,ISNULL(Sec.SectorName, '') as SectorName, ISNULL(I.PlotNo, '') as PlotNo, MD.ClientPic from MemberMaster MM " +

                                                                        " inner join MembersDetail MD on MD.MemberShipID = MM.MemberShipID and MD.Srno = 1 " +

                                                                        " inner join MasterFileDetail FD on FD.MembershipID = MM.MemberShipID and FD.IsOwner = 1 and FD.IsTransfered = 1 " +

                                                                        " inner join MasterFile FM on FM.FileID = FD.FileID and FM.Cancel = 0 " +

                                                                        " inner join Sectors Sec on Sec.Phase_ID = FM.PhaseId and Sec.Sector_ID = FM.Sector_ID " +

                                                                        " inner join PlotsInventory I on I.Phase_ID = FM.PhaseId and I.Plot_ID = FM.Plot_ID " +

                                                                   " where MM.MemberShipID = '" + username + "' and MM.IsApproved = 1 and RTRIM(MM.LoginPwd) = '" + password + "' and MM.IsActive = 1 " +

                                                                   " order by FD.FileID", con)


                            }

                        }



      }


繁花如伊
浏览 155回答 3
3回答

慕哥6287543

如果您需要在 Controller-Action 级别做出此决定,请创建一个属性:public class SelectorAttribute : ActionMethodSelectorAttribute    {        public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)        {            int a;            return int.TryParse((string)controllerContext.HttpContext.Request.QueryString["username"], out a);        }    }并有两个动作定义为:[Selector]public ActionResult Login(int username, string password){    //Code here}和public ActionResult Login(string username, string password){    //Code here}希望能帮助到你。干杯..

米脂

您可以使用:bool result = Int32.TryParse(username, out number);if (result){    //call other function      }else{    //call mLogin}
打开App,查看更多内容
随时随地看视频慕课网APP