I have combed the Internet for anything slightly related to this (and other sites) for several days trying to figure this out. Please help (-:
What I have is a form with a lot of textboxes on it. Some are required, some are not. I have 2 boxes that are for Social Security Numbers and they have to match, named "TaxID" and "SSNAgain".
I didn't name the first one, as I would have named it SSN, but someone else did that. I have already written the code to check the match in both boxes so I had to make them both required and they have to have 9 digits in them. Problem is, I only need to submit the first one "TaxID" and not the "SSNAgain" box to the database.
Nothing I try will work, it just keeps either refreshing the page and coming back to the "SSNAgain" box with it highlighted in pink (probably because there's no field in the database for it), or it sends me to the generic error page provided by ASP.NET MVC when we set this up several years ago.
Also, I had to change the ssn boxes to
@Html.PasswordFor
boxes because our company just got bought out the other day and these guys wanted the SSN boxes covered with the little dots like password boxes are. Below are some things I have been trying but to no avail. Thanks in advance to ANYONE that can help me with this matter.
NOTHING I try will work. I just need to submit the page to the database and NOT submit the contents from SSNAgain. But the clients do have to put in their SSN number and it has to match what's in TaxID. At this point, I'm just grasping at straws here.
What I have tried:
public class IndividualController : Controller
{
private DataForm18Entities db = new DataForm18Entities();
public ActionResult Index()
{
System.Threading.Thread.Sleep(2000);
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index([Bind(Include = "RowID,TaxID,FirstName,LastName,BirthDate,blah,blah,blah)] DataForm_Individual dataForm_Individual)
{
//ModelState["SSNAgain"].Errors.Clear();//tried putting this here...
if (ModelState.IsValid)
{ //ModelState["SSNAgain"].Errors.Clear();//probably tried putting this here...
try
{
db.DataForm_Individual.Add(dataForm_Individual);
db.SaveChanges();
//some other code to send success email
return View("Success");
}
catch (Exception e)
{
//code to send error info to email
return View("Error");
}
}
return View(dataForm_Individual);
}
}
//Here's my annotations:
[Required(ErrorMessage = "SSN is required")]
[RegularExpression(@"[0-9]*\.?[0-9]+", ErrorMessage = "SSN must be numbers only.")]
[StringLength(9, MinimumLength = 9, ErrorMessage = "Invalid SSN Length")]
[DataType(DataType.Password)]
[Display(Name = "SSN", Description = "Please enter your Social Security Number without spaces or dashes")]
public string TaxID { get; set; }
[Required(ErrorMessage = "SSN is required")]
[RegularExpression(@"[0-9]*\.?[0-9]+", ErrorMessage = "SSN must be numbers only.")]
[StringLength(9, MinimumLength = 9, ErrorMessage = "Invalid SSN Length")]
[DataType(DataType.Password)]
[Display(Name = "Confirm SSN", Description = "Please enter your Social Security Number again without spaces or dashes")]
public string SSNAgain { get; set; }
And below is my JavaScript. I even tried doing it that way.
$(function () {
$("#IndvForm").submit(function () {
if ($(this).valid()) {
$("#loading").fadeIn();
var opts = {
lines: 12,
length: 7,
width: 4,
radius: 10,
color: '#000',
speed: 1,
trail: 60,
shadow: false,
hwaccel: false
};
var target = document.getElementById('loading');
var spinner = new Spinner(opts).spin(target);
return true;
}
});
});