Javacscript confirmation is automatically posting form

FL

New Member
I have a Partial View which contains a file input for uploading files(s). A User on this view will select a file from their workstation and click the upload button. The upload click submits the form to an action method and the files are parsed and the same view is returned to auto-populate a few fields on the view.Everything as is, is working perfectly. I am adding a new requirement to the existing view which is as following:Requirement User selects a file and clicks the upload button. Once the upload button is clicked, a JavaScript confirmation dialog is displayed to the users which contains two button options before the form is submitted to the controller action method. These buttons are "Buffer Run Parsing" and "Normal Parsing". Clicking any of these buttons will post to the controller action method. In the controller action method upon post, My goal is to capture which button they pressed and based on the button pressed I select the file parsing logic accordingly.The ProblemI created a JavaScript function which does display the two buttons but the dialog box automatically disappears and the form posts to the controller. I would like it to not post until I click either button with the confirmation.Here is what I am doing: Main View:\[code\]@using (Html.BeginForm("Create", "RunLogEntry", FormMethod.Post, new { id = "form", enctype = "multipart/form-data"})){ <div id="main"> @Html.Partial("_RunLogEntryPartialView", Model) </div>}\[/code\]Partial View:\[code\]<button name="submit" class="art-button" type="submit" value="http://stackoverflow.com/questions/15693149/Upload" onclick="initUploadDailog();return false;" style="width: 100px"> Upload</button><div id="uploadConfirmation" style="font-size: 10px; font-weight: normal; overflow: scroll; width: 800px; height: 450px; display: none;"></div>\[/code\]JS Function:\[code\] function initUploadDailog(e) { currentForm = $(this).closest('form'); UploadDialog = $("#uploadConfirmation").dialog({ modal: true, width: 400, autoOpen: true, title: 'Please select parsing type for Test Completed Computation', buttons: { "Normal Parsing": function () { $("#hiddenInput").val("Normal"); alert(currentForm.innerHtml()); currentForm.submit(); }, "Buffer Parsing": function () { $("#hiddenInput").val("Buffer Run"); currentForm.submit(); } } }); }\[/code\]Controller:\[code\] [HttpPost] [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(RunLogEntry runLogEntry, String ServiceRequest, string Hour, string Minute, string AMPM, string submit, IEnumerable<HttpPostedFileBase> file, String AssayPerformanceIssues1, List<string> Replicates) {}\[/code\]
 
Back
Top