如何使用ASP.net MVC将json结果保存到多个表中?

时间:2019-05-30 02:25:14

标签: c# json asp.net-mvc

我有一个清单,想要检索所有json格式的检查值并将结果保存到多个表中,如何编写代码?

检索json中所有检查的值并得到结果

清单的UI:

                           <tr class="tableResult1">
                               <td>Appliances</td>
                               <td>
                                   <table width="100%" border="0" cellspacing="0" cellpadding="1">
                                       <tr>
                                           <td width="1%">
                                               <input type="hidden" name="lpgChecklist.answers(APPLIANCES_OVEN).questionId" value="3" />
                                               <input type="hidden" name="lpgChecklist.answers(APPLIANCES_OVEN).answerListId" value="1" />
                                               <input type="checkbox" name="lpgChecklist.answers(APPLIANCES_OVEN).value" value="OVEN" checked />
                                           </td>
                                           <td>Oven</td>
</tr>
</table>

用于检索已检查列表的javascript:


  var maxChkLstIndex = 0;
        var currentChkLst = 1;  
        var chkLstCount = maxChkLstIndex;
        var startPattern = "lpgChecklist.answers(";
        var startPattern1 = "pipeChecklist.answers(";
        var startPattern2 = "dimsumChecklist.answers(";
        var endValuePattern = ").value";
        var endAnswerPattern = ").answerListId";
        var endQuestionPattern = ").questionId";
        var surveyJSON = getElement("surveyJSON").cloneNode();

            answers = {};


            var lpgCheck = document.getElementsByTagName("input")
            console.log(lpgCheck.length);

            for (var i = 0; i < lpgCheck.length; i++) {
                var oid = lpgCheck[i].name;
                var type = lpgCheck[i].type;
                if (oid != null && oid != "") {
                    if (oid.startsWith(startPattern) && oid.endsWith(endValuePattern)) {
                        var objname = oid.substring(startPattern.length, oid.length - endValuePattern.length);
                        if (type == "checkbox") {
                            if (lpgCheck[i].checked == true) {
                                eval("answers." + objname + "={};");
                                eval("answers." + objname + ".answerListId=getElement('" + startPattern + objname + endAnswerPattern + "').value;");
                                eval("answers." + objname + ".questionId=getElement('" + startPattern + objname + endQuestionPattern + "').value;");
                                eval("answers." + objname + ".value=getElement('" + startPattern + objname + endValuePattern + "').value;");
                            }
                        } else if (type == "text") {
                            if (lpgCheck[i].value != "") {
                                eval("answers." + objname + "={};");
                                eval("answers." + objname + ".questionId=getElement('" + startPattern + objname + endQuestionPattern + "').value;");
                                eval("answers." + objname + ".value=getElement('" + startPattern + objname + endValuePattern + "').value;");
                            }
                        }
                    }
                }
            }

            console.log(answers);
        }

0 个答案:

没有答案