c# - WEB API MVC4 - using datagrid to post -
i have written mvc4 webapi takes companyid, name , posts db. need alter in such way user can come in multiple values companyid names , save db in 1 shot. how can that? here's code
--index.cshtml <div id="body"> <section class="featured"> <div class="content-wrapper"> <hgroup class="title"> <h1>welcome web api!</h1> </hgroup> </div> </section> <section class="content-wrapper main-content clear-fix"> <p> api documentation: @html.actionlink("api", "index", "help", new { area = "" }, null) </p> <p> update/insert company info: <a href="companies.html">click here!</a> </p> </section> </div> --companies.html
<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> </head> <body> <script> var overrides = array(); function parseform(button) { var companyid = $("#companyid").val(); var companyname = $("#companyname").val(); var lst = { companyid: companyid, companyname: companyname } if (button.attr('value') === "post") { console.log("posting : " + lst.tostring()); postdata(lst); } else { console.log("error"); } } function postdata(lst) { $("#response").text("posted"); $.ajax({ type: "post", datatype: "json", url: "api/company/", data: lst, xhrfields: { withcredentials: true }, success: function (data, status, xhr) { console.log(status); $("#response").text(status) }, error: function (xhr, status, error) { console.log(xhr.responsetext); var json = jquery.parsejson(xhr.responsetext); console.log(json); $("#response").text(status) alert(json.message); } }); } $(document).ready(function () { $('input:button').click(function () { parseform($(this)); }); }); </script> <div id="form"> <label for="companyid">companyid:</label><input type="text" id="companyid" /><br /> <label for="companyname">companyname:</label><input type="text" id="companyname" /><br /> <input type="button" id="post" value="post"/> </div> <div id="response"> </div> </body> </html in companiescontroller, have written phone call stored procedure post method save 1 record @ time. how can post many rows @ time & changes should html file.
thanks r
how did declared variables in model. operating multivalued types, seek this:
private icollection<string> _variable; public icollection<string> variablename { { if (_variable == null) { homecoming new collection<string> {""}; } else { homecoming _variable; } } set { _variable = value; } } c# asp.net-mvc-4
No comments:
Post a Comment