What I want is to add an object routed value when the user submits the form (ajax.beginform)
Depending on what the user chooses in the ConfirmDone function, i want to add an integer (SaveOption)
But i don't really know how to do it.
The confirmdone function is called but that's it, my controller action is'nt called. I probably need to return something?
Some Code: the start of the form
@using (Ajax.BeginForm("CreateFunctiebeschrijvingPartial", "Functiebeschrijving", new AjaxOptions { UpdateTargetId = "Functiebeschrijving", OnBegin = "return ConfirmDone()", OnSuccess = "handleSuccess" }, new {@id = frmID}))
{
The confirmdone function
function ConfirmDone() {
if (confirm("This form saves default as Concept, would you like to save it as completed? 1 = Completed, 2 = Concept")) {
//option 1: save as completed
$('#frmID').attr("SaveOption", 1);
}
else {
//Option 2: save as concept
}
}
The start of my controller action
//
// POST: /FunctieBeschrijving/CreateFunctiebeschrijvingPartial
[HttpPost]
public ActionResult CreateFunctiebeschrijvingPartial(NieuweFunctiebeschrijvingViewModel nfvm, int SaveOption)
{
When i don't use the confirm function, everything is posted as it should be!
function addDataToUrl(url, name, value){
var sep = url.indexOf('?') === -1 ? '?' : '&';
return url + sep + name + '=' + value;
}
function ConfirmDone() {
var form = document.getElementById('frmID');
if (confirm("This form saves default as Concept, would you like to save it as completed? 1 = Completed, 2 = Concept")) {
//option 1: save as completed
form.setAttribute('action',
addDataToUrl(form.getAttribute('action'), 'SaveOption', '1'));
}
else {
// Option 2: save as concept
}
}