Click here to Skip to main content
15,887,476 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is my code
@{
Layout = null;
}
@{
ViewBag.Title = "EnterOTP";
}

EnterOTP


@*@ViewBag.otp*@
An Otp is send to your Email ,copy and paste here to confirm









var verifyotp = function () {
var otp = $('#enterotp').val();
debugger
$.ajax({
url: "/Signup/VerifyOTP",
data: otp,
type: "post",
success: function (data) {

debugger
if (data == true) {
alert("Verified successfully");
window.location = "/Login/Login";
}
else {
alert("Failed to verify OTp");
}
}
})
}


this is my action method
public ActionResult EnterOTP()
{
return View();
}

[HttpPost]
public JsonResult VerifyOTP(string otp)
{
using (var db = new OfficeEntities())
{
Account account = new Account();
db.Accounts.Where(x => x.Otp.ToString() ==otp );
// db.Entry(IsActive).State = EntityState.Modified;
account.IsActive = true;
db.SaveChanges();

}

return Json(, JsonRequestBehavior.AllowGet);

}

What I have tried:

i want to verify this
public ActionResult EnterOTP()
{
return View();
}

[HttpPost]
public JsonResult VerifyOTP(string otp)
{
using (var db = new OfficeEntities())
{
Account account = new Account();
db.Accounts.Where(x => x.Otp.ToString() ==otp );
// db.Entry(IsActive).State = EntityState.Modified;
account.IsActive = true;
db.SaveChanges();

}

return Json(, JsonRequestBehavior.AllowGet);

}
Posted
Comments
jimmson 22-Aug-19 6:53am    
You'll need to dig up the real exception. Internal server error is generic error saying there's something wrong on the server side.
Richard Deeming 22-Aug-19 6:57am    
Error 500 means there was an error in your server-side code. You need to find the details of that error. Try examining the AJAX request in the network tab of your browser's developer tools, to see if the server is returning a detailed error message.

Having said that, the server-side code you've posted doesn't make any sense. You create a new Account object; declare a query but never execute it; set a property on the new Account instance; and save the database changes, of which there will be none. I'd expect something more like:
Account account = db.Accounts.FirstOrDefault(x =>. x.Otp == otp);
if (account == null) return Json(false);
account.IsActive = true;
db.SaveChanges();
return Json(true);


NB: Your method only allows POST requests, so there's no point specifying the JsonRequestBehavior.AllowGet option.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900