微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我想从提交按钮调用 getmethod json 结果

如何解决我想从提交按钮调用 getmethod json 结果

我想验证按钮在输入 otp 时给消息 otp 有效,如果 otp 有效,它应该重定向一个控制器动作,如果不是,它应该显示错误有效的无效验证码或 otp

查看:

   @{
       Layout = "~/Views/Shared/_Layout.cshtml";
       ViewBag.Title = "SelfService";
   }
   @*<script src="../../Scripts/jquery-1.10.2.js"></script>*@
   <script src="~/Scripts/jquery-1.7.2.min.js"></script>
   <script>
       function GetoTP() {
           debugger;
           var mobileno = $('#MobileNo').val();
           var emailid = $('#EmailID').val();
           $.ajax({
               url: '/SelfService/GetoTP?MobileNo=' + mobileno + '&EmailID=' + emailid,type: 'GET',cache: 'false',success: function (result) {
                   debugger;
                   alert("OTP successfully send!!");
               }
           });
           return true;
       }
       function verifyOTP() {
           debugger;
           var mobileno = $('#MobileNo').val();
           var emailid = $('#EmailID').val();
           var otp = $('#OTP').val();
           $.ajax({
               url: '/SelfService/SelfService?MobileNo=' + mobileno + '&EmailID=' + emailid +'&OTP=' + otp,success: function (result) {
                   debugger;
                   swal(result);
               }
           });
           return true;
       }
     
       
   </script>

   @using (Html.BeginForm("SelfService","Selfservice"))
   {
       @Html.ValidationSummary(true)
       <fieldset>
           <legend>Verification</legend>
           <div class="demo-container">
               <div class="editor-label">
                   @Html.LabelFor(model => model.MobileNo)
               </div>
               <div class="editor-field">
                   @Html.TextBoxFor(model => model.MobileNo,new { @readonly = "readonly" })
                   @Html.ValidationMessageFor(model => model.MobileNo)
               </div>
               <div class="editor-label">
                   @Html.LabelFor(model => model.EmailID)
               </div>
               <div class="editor-field">
                   @Html.TextBoxFor(model => model.EmailID,new { @readonly = "readonly" })
               </div>
               <input type="button" value="Send OTP" class="btn btn-success" onclick="GetoTP();" />
              
              
               
               <br><nbsp;>
                   <div class="editor-label">
                       @Html.LabelFor(model => model.Otp)
                   </div>
                   <div class="editor-field">
                       @Html.TextBoxFor(model => model.Otp)
                       @Html.ValidationMessageFor(model => model.Otp)
                       <p class="Errormesg">  @ViewBag.message</p>
                   </div>
                   @*Html.MathCaptcha()*@
                   @Html.Captcha(3)
                   <br />
                   <p class="Error">  @ViewBag.ErrMessage </p>
                   @*<p class="Errormesg">  @ViewBag.message</p>*@
                   <div>
                       <input Id="subbutton" type="submit" value="submit" onclick="verifyOTP(this)" formaction=@Url.Action("SelfService") formmethod="get" class="btn btn-primary"/>
                   </div>
           </div>
       </fieldset>   
  }  

控制器:

using System.Linq; 
using System.Web.Mvc; 
using DemographicAuthentication.Models; 
using CaptchaMvc.HtmlHelpers; 
using ServerDBDAL; 
using System; 
using System.Collections.Generic; 
using System.Collections.Specialized; 
using System.Configuration; 
using System.IO; 
using System.Net; 
using System.Xml.Linq;

namespace DemographicAuthentication.Controllers 
{
    public class SelfServiceController : Controller
    {
        // GET: /SelfService/
        string message;
        ServerDBDAL.DemoAuthEntities objdatabase = new ServerDBDAL.DemoAuthEntities();
        SelfEkyc objcls = new SelfEkyc();
        string refId;

           [HttpPost,ValidateInput(false)]
           public ActionResult SelfService(FormCollection fc)
           {
               string msg = string.Empty;
               msg = fc["Request"];
               //tring dcdrypteddata = Encoding.UTF8.GetString(Convert.FromBase64String(msg));
               if (msg != null)
               {
                   XDocument SelfKYC = new XDocument();
                   SelfKYC = XDocument.Parse(msg);
                   string vendorid = SelfKYC.Element("SelfKYCRequest").Element("vendorID").Value;
                   string Password = SelfKYC.Element("SelfKYCRequest").Element("Password").Value;
                   string refid = SelfKYC.Element("SelfKYCRequest").Element("refId").Value;
                   string EmailID = SelfKYC.Element("SelfKYCRequest").Element("EmailId").Value;
                   string MobileNo = SelfKYC.Element("SelfKYCRequest").Element("Mobile").Value;
                   string Showresponse = SelfKYC.Element("SelfKYCRequest").Element("Showresponse").Value;
                   string ResponseURL = SelfKYC.Element("SelfKYCRequest").Element("Redirecturl").Value;
                   string ServiceType = SelfKYC.Element("SelfKYCRequest").Element("ServiceType").Value;
                   TempData["vendorid"] = vendorid;
                   TempData["Password"] = Password;
                   TempData["refId"] = refid;
                   TempData["EmailID"] = EmailID;
                   TempData["MobileNo"] = MobileNo;
                   TempData["showresponce"] = Showresponse;
                   TempData["ResponseURL"] = ResponseURL;
                   TempData["ServiceType"] = ServiceType;
                   string vendorAuth = objdatabase.USP_Authenticatevendor(vendorid,Password).FirstOrDefault();
                   if (vendorAuth == "vendor Authenticated Successfully")
                   {
                      
                       String refId = "UAfKsVZ";
                       var result = objdatabase.USP_GetMobileNumber(refId).FirstOrDefault();
                       objcls.EmailID = result.EmailID;
                       objcls.MobileNo = result.MobileNo;
                       TempData["refId"] = refId;
                     
                  }
                else
                   {
                       string vmessage= "Transaction can not be processed as vendor Not Available";
                      return Json(vmessage,JsonRequestBehavior.AllowGet);
                   }
               }
               return View(objcls);
           }
           [HttpGet]
           //To Generate Otp
           public String GetoTP(string MobileNo,string EmailID,string refId)
           {
               // SelfEkyc objcls = new SelfEkyc();
               Random objRandomOtp = new Random();
               string generatedotp = objRandomOtp.Next(1000,9999).ToString();
               string refid = TempData["refId"].ToString();
               TempData["refId"] = refId;
               //return objcls.OTP = generatedotp;
               var insertotp = objdatabase.USP_InsertOTP(MobileNo,refid,EmailID,generatedotp,"","").ToString();
               //ViewBag.otp = objcls.Otp;
               TempData["refid"] = refid;
               return ViewBag.otp = generatedotp;
           }
           [HttpGet]
           //[HttpPost]
           public ActionResult SelfService(String EmailID,String MobileNo,int OTP,String refId)
           {
               string refid = TempData["refid"].ToString();
               TempData["refid"] = refId;
               SelfEkyc objcls = new SelfEkyc();
               var result = objdatabase.USP_ValidateOTP(EmailID,MobileNo,OTP,refid).FirstOrDefault();
               //objcls.EmailID = result.EmailID;
               //objcls.MobileNo = result.MobileNo;
               // objcls.Otp = result.OTP;     
               if (result == null)
               {
                   message = "OTP NOT VALID";
               }
               else
               {
                   message = "OTP Valid";
               }
               // Code for validating the CAPTCHA 
               if (this.IsCaptchaValid("Captcha is not valid"))
               {
                   ViewBag.message = message;
                   //return View(message);
                   return Json(message,JsonRequestBehavior.AllowGet);
               }
               ViewBag.ErrMessage = "Error: captcha is not valid.";
               return View();
        }
    } 
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。