Question

I have a piece of code that when the user clicks the save button I need to query the database and see if this new record will create a duplicate. If it will create a duplicate I need it to pop up a confirmation box that informs the user that the new record is a potential dup, but still allow the save to continue if they select yes. I have the dup check working but need to know how to pop the confirmation box if needed and then continue with the save if no dup is found or if the user select to save anyways.

Was it helpful?

Solution

You need to create an action with JsonResult in controller which will validate your record. You can call it from Jquery and create popup with your requirement in Jquery. you can modify the following basic example:

C# code

public class YourController : Controller
{
public JsonResult ValidateRecord(clsType objType)
{       
     Boolean isDuplicate = CheckDup(objType);
     return Json(new {result = isDuplicate}, JsonRequestBehavior.AllowGet);
}
}

JavaScript

function ValidateSubmit() 
{
$.getJSON('/Your/ValidateRecord', { TypeProp1:TypeValue1 }, function(data) {
    var showPopUp=data.result;
    if(showPopUp){
    //Your popup and form submission code 
    }
});

}

Please mark as answer if you find it helpful

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top