c# - How to pass individual records from a list to a Dialog in MVC and allow user to accept or reject the record passed using buttons inside the dialog -
i struggling figure out, have mvc app upload of csv file few, pass list of data stored procedure performs validation on records csv file, need write validated response list dialog box individually user can accept or reject record, on click of accept go next record , on, if reject button clicked them close page (this got working simple close function in jquery dialog). struggling pass data dialog click accept move next record , display in dialog.
please see code below see how far have come.
i have 2 view, 1 index uploads csv , display list of data , there button on view called validate claims, opens dialog box, question lies.
here index view:
@{ viewbag.title = "home page"; } <script src="~/scripts/jquery-ui-1.11.4.min.js"></script> <script src="~/scripts/jquery-ui-1.11.4.js"></script> <link href="~/content/themes/base/dialog.css" rel="stylesheet" /> @using csvsupplierclaims.models @model list<csvsupplierclaims.models.supplierclaimsuploaddisplaylist> <button type="submit" id="validateclaims" value="validate claims" size="5" data-url="@url.action("validateclaims", "home", new { area = "supplierclaimuplaod" })">validate claims</button> <input type="submit" value="import claims crm" size="5" /> <div id="dialog" title="claims validation"> accept or reject following record <p> <table> <tr> <td>st key</td> <td>supplier claim</td> <td>orig inv</td> <td>error</td> <td>system cost</td> </tr> @if (model != null) { foreach (var claim in model) { <tr> <td>@claim.st_key</td> <td>@claim.supplierclaim</td> <td>@claim.originv</td> <td>@claim.error</td> <td>@claim.systemcost</td> </tr> } } </table> </p> </div> <script type="text/javascript"> $(function () { $("#dialog").dialog({ autoopen: false }); $("#validateclaims").click(function () { $("#dialog").dialog("open"), $("#dialog").dialog({ resizable: true, height: 300, width: 500, modal: true, closeonescape: true, buttons: { "accept": function () { **//this question lies** $(this).dialog("close"); $(this).empty(); }, "reject": function () { alert('validation cancelled..'); $(this).dialog("close"); } } }); }); }); </script> <div class="csstablegenerator"> <table> <tr> <td>no.</td> <td>action</td> <td>lineno</td> <td>totalclaim</td> <td>claimreference</td> <td>currency</td> </tr> @if (model != null) { int counter = 0; foreach (var c in model) { counter++; <tr> <td>@counter</td> <td>@c.action</td> <td>@c.lineno</td> <td>@c.totalclaim</td> <td>@c.claimreference</td> <td>@c.currency</td> </tr> } } </table> </div> <form action="" method="post" enctype="multipart/form-data"> <table style="margin-top:150px"> <tr> <td> <label for="file"> filename</label> </td> <td> <input type="file" name="file" id="file" /> </td> <td> <input type="submit" value="upload" /> </td> </tr> </table> </form>
here controller:
using csvhelper; using csvsupplierclaims.models; using system; using system.collections.generic; using system.globalization; using system.io; using system.linq; using system.web; using system.web.mvc; using crm; using system.data.sqlclient; using system.data; namespace csvsupplierclaims.controllers { public class homecontroller : controller { public actionresult index(httppostedfilebase file) { string path = null; list<supplierclaimsuploaddisplaylist> supplierclaimsdata = new list<supplierclaimsuploaddisplaylist>(); try { if (file.contentlength > 0) { var filename = path.getfilename(file.filename); path = appdomain.currentdomain.basedirectory + "upload\\" + filename; file.saveas(path); var csv = new csvreader(new streamreader(path)); var supplierlist = csv.getrecords<supplierclaimsupload>(); foreach (var supplier in supplierlist) { supplierclaimsuploaddisplaylist supplieruploaddisplay = new supplierclaimsuploaddisplaylist(); supplieruploaddisplay.action = supplier.action; supplieruploaddisplay.lineno = supplier.lineno; supplieruploaddisplay.totalclaim = supplier.totalclaim; supplieruploaddisplay.claimreference = supplier.claimreference; supplieruploaddisplay.currency = supplier.currency; supplierclaimsdata.add(supplieruploaddisplay); } } } catch { viewdata["error"] = "uplaod failed"; } tempdata["claimsresponse"] = supplierclaimsdata; return view(supplierclaimsdata); } public actionresult validateclaims() { list<supplierclaimsuploaddisplaylist> supplierclaimsdata = (list<supplierclaimsuploaddisplaylist>)tempdata["claimsresponse"]; //= new list<supplierclaimsuploaddisplaylist>(); supplier_claim_upload_results supplierclaimuplaod = new supplier_claim_upload_results(); var sqlconnection = "data source=wmvsql02;initial catalog=embrace;integrated security=true;"; using (sqlconnection conn = new sqlconnection(sqlconnection)) { try { foreach (var claim in supplierclaimsdata) { sqlcommand cmd = new sqlcommand(); cmd.commandtimeout = 60; sqldatareader reader; cmd.commandtext = "crm.supplier_claim_upload"; cmd.commandtype = commandtype.storedprocedure; cmd.parameters.add("@invoice", sqldbtype.nvarchar).value = claim.lineno; cmd.parameters.add("@amount", sqldbtype.nvarchar).value = claim.totalclaim; cmd.connection = conn; conn.open(); reader = cmd.executereader(); while (reader.read()) { claim.st_key = reader.getstring(reader.getordinal("st_key")); if (claim.supplierclaim != null) { claim.supplierclaim = reader.getstring(reader.getordinal("supplier_claim")); } else if (claim.supplierclaim == null && claim.originv == null && claim.systemcost == null) { if (claim.error != null) { claim.error = reader.getstring(reader.getordinal("error")); } else if (claim.error == null) { claim.supplierclaim = reader.getstring(reader.getordinal("supplier_claim")); } } if (claim.originv != null) { claim.originv = reader.getstring(reader.getordinal("orig_inv")); } else if (claim.originv == null) { if (claim.error != null) { claim.error = reader.getstring(reader.getordinal("error")); } else if (claim.error == null) { claim.originv = reader.getstring(reader.getordinal("orig_inv")); } } if (claim.systemcost != null) { claim.systemcost = reader.getstring(reader.getordinal("system_cost")); } else if (claim.systemcost == null) { if (claim.error != null) { claim.error = reader.getstring(reader.getordinal("error")); } else if (claim.error == null) { claim.systemcost = reader.getstring(reader.getordinal("system_cost")); } } } conn.close(); } } catch (exception ex) { viewbag.error = ex.message + ex.innerexception; } } return view(supplierclaimsdata); } } }
just reiterate issue, need validate claims button click event pass list individual records dialog, once user clicks accept code should add record new list , dialog must display next record. comfortable server side code, struggling client side jquery read list , pass records dialog. appreciated.
Comments
Post a Comment