调试代码时出现问题。用户已在该字段中注册,并转到了另一页。但是当转到另一个页面时,所有参数都包含在URL中。 例: http://localhost:56767/Pendaftaran/VerifyEmail?Role=3&FirstName=Abu&LastName=Mutalib&ICNumber=8812511469&Gender=1&Email=abu%40gmail.com&Password=aaabbb&ConfirmPassword=aaabbb&State=16&MobileNumber=012-7415511
这在sql服务器上使用存储过程数据库。
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult AddParticipant(RegistrationModel obj)
{
try
{
if (ModelState.IsValid)
{
if (this.IsCaptchaValid("Captcha is not valid")) //Added Captcha 17 May 2019 -Aidil-
{
if (obj.Role == 2) //Add if else for club 17 May 2019 -Aidil-
{
if (obj.CLubRegistration != null)
{
//Add Stored Procedured -Aidil- 15 May 2019
connection();
SqlCommand com = new SqlCommand("uspRegisterParticipant", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@Role", obj.Role);
com.Parameters.AddWithValue("@ClubReg", obj.CLubRegistration); //Added ClubRegistration 16 May 2019 -Aidil-
com.Parameters.AddWithValue("@FirstName", obj.FirstName);
com.Parameters.AddWithValue("@LastName", obj.LastName);
com.Parameters.AddWithValue("@ICNumber", obj.ICNumber);
com.Parameters.AddWithValue("@Gender", obj.Gender);
com.Parameters.AddWithValue("@Email", obj.Email);
com.Parameters.AddWithValue("@Password", obj.Password);
com.Parameters.AddWithValue("@State", obj.State);
com.Parameters.AddWithValue("@MobileNumber", obj.MobileNumber); //Added MobileNumber 16 May 2019 -Aidil-
con.Open();
int i = com.ExecuteNonQuery();
con.Close();
//End Added Stored Procedured -Aidil- 15 May 2019
}
}
else
{
connection();
SqlCommand com = new SqlCommand("uspRegisterParticipant", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@Role", obj.Role);
com.Parameters.AddWithValue("@FirstName", obj.FirstName);
com.Parameters.AddWithValue("@LastName", obj.LastName);
com.Parameters.AddWithValue("@ICNumber", obj.ICNumber);
com.Parameters.AddWithValue("@Gender", obj.Gender);
com.Parameters.AddWithValue("@Email", obj.Email);
com.Parameters.AddWithValue("@Password", obj.Password);
com.Parameters.AddWithValue("@State", obj.State);
com.Parameters.AddWithValue("@MobileNumber", obj.MobileNumber); //Added MobileNumber 16 May 2019 -Aidil-
con.Open();
int i = com.ExecuteNonQuery();
con.Close();
//End Added Stored Procedured -Aidil- 15 May 2019
}
return RedirectToAction("VerifyEmail", obj); //Update RedirectAction 27 May 2019 -Aidil-
}
ViewBag.ErrMessage = "Error: captcha is not valid.";
//return View();
}
return View();
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
return View();
}
}
// GET: Pendaftaran/VerifyEmail
//Added VerifyEmail 27 May 2019 -Aidil-
[HttpGet]
public ActionResult VerifyEmail(EmailVerificationModel obj)
{
try
{
//Add Stored Procedured -Aidil- 27 May 2019
connection();
SqlCommand com = new SqlCommand("uspDisplayNameForVerification", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@FirstName", obj.FirstName); //Added called from AddParicipant 28 May 2019 -Aidil-
com.Parameters.AddWithValue("@LastName", obj.LastName); //Added called from AddParicipant 28 May 2019 -Aidil-
con.Open();
//int i = com.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(com);
con.Close();
return View(obj); //Update view () to view(obj) -Aidil- 29 May 2019
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
return View();
}
}
//End Added VerifyEmail 27 May 2019 -Aidil-
}
据说我只想显示这个: http://localhost:56767/Pendaftaran/VerifyEmail?Role=3
答案 0 :(得分:0)
您正在传递整个对象,同时重定向了obj,这将使所有参数失效 您只需传递必填字段
尝试
return RedirectToAction("VerifyEmail", obj.Role);
这将把Role参数作为下一个查询字符串。