Skip to content Skip to sidebar Skip to footer

How To Pass The Email Id Value After Checking Captcha In Asp.net Mvc4?

I am new one to Asp.Net Mvc4 with Entity Framework. Now i am doing Captcha verification for Forgot Password. As my code, I it is passing the Email id value to Controller when i am

Solution 1:

What is happening currently? I mean, how is the application behaving? EDIT: You can try server side validation for example if you have a field to validate you can add a validation tag there.For example:

<inputtype="text" name="SampleTextBox"id="SampleTextBoxId"/>
 @Html.ValidationMessage("SampleTextBox", "*")

Then you go to the controller and add this kind of code:

if (!string.IsNullOrEmpty(SampleTextBox))
{
//Your Code.
}
  else
{
  ViewData.ModelState.AddModelError("SampleTextBoxId", "Text should not be empty.");
}

Use Model.IsValid as your condition to write your main code. Model.IsValid becomes False if ViewData.ModelState.AddModelError("SampleTextBoxId", "Text should not be empty."); is executed. This is a way to add validations. You can check for your valid/invalid captcha in your controller itself and throw error. For Example:

if (IsValidCaptcha(enteredCaptcha))
{
//Code
}
else
{
ViewData.ModelState.AddModelError("captchaId", "Enter valid captcha");
}

Lastly, add a validation summary to your page

@Html.ValidationSummary("Error Messages")

Post a Comment for "How To Pass The Email Id Value After Checking Captcha In Asp.net Mvc4?"