Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
76 views
in Technique[技术] by (71.8m points)

javascript - how to add record in datatable in mvc view using js

am new in asp.net mvc and js I want to add record in detail table her is my html code

Add To List
                        <div class="form-group">
                            <label for="Name"> Account Name: </label>
                            <select id="Accounts" class="form-control">
                                <option value="">Select Account</option>
                            </select>
                            <small id="error_Accounts" class="form-text error_msg">Select Account from list</small>
                        </div>
                        <div class="form-group" id="medicineDetails1">
                            @*<p style="font-size:11px" id="medicineDetails"></p>*@
                            @*buying price : <strong>12.99</strong>, Batch No: <strong>2255662</strong>*@

                        </div>

                        <div class="col-md-4">
                            <div class="form-group">
                                <label for="Quantity"> Qty : </label>
                                @Html.TextBox("Qty1", null, new { @class = "form-control", @type = "number", id = "Qty1" })
                                <small id="error_Qty1" class="form-text error_msg"></small>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label for="Rate">  : Rate</label>

                                @Html.TextBox("Rate", null, new { @class = "form-control", @Value = "0", @type = "number", id = "Rate" })
                                <small id="error_Rate" class="form-text error_msg"></small>
                            </div>
                        </div>
                        <br />
                        <br />


                        <div class="form-group" style="width:250px;float:left">
                            <label for="B">Narration </label>
                            @Html.TextBox("Narration", null, new { @class = "form-control", id = "Narration", @placeholder = "Enter some Narration" })
                            <small id="error_Narration" class="form-text error_msg">Narration  required</small>

                        </div>
                        <div class="col-md-4" style="float:left;width:150px">
                            <div class="form-group">
                                <label for="B">Amount</label>
                                @Html.TextBox("Amount1", null, new { @class = "form-control", @Value = "0", @type = "number", id = "Amount1" })
                                <small id="error_Amount1" class="form-text error_msg"> Amount is Requrid</small>
                            </div>
                        </div>

                        <div class="form-group col-md-4" style="margin-left:20px;width:100px">
                            <label for="Drcr"> Dr/Cr: </label>
                            @Html.DropDownList("Drcr", new List<SelectListItem>
                                {
                                    new SelectListItem() {Text = "Dr", Value="Dr"},
                                    new SelectListItem() {Text = "Cr", Value="Cr"},
                                },  new { @class = "form-control", onchange = "blankme(this.id)" })

                            <small id="error_drcr" class="form-text error_msg"> Drcr is Requrid</small>
                        </div>
                        <br><br />
                        <div class="form-group m-b-0">
                            <button type="submit" id="addToIe" class="btn btn-info">
                                Add To Expenses or Income
                            </button>
                        </div>

                    </form>
                </div>

Expenses/Income Sr Account Name Qty Rate Narration Amount Dr/Cr
                                        </tr>
                                    </thead>
                                    <tbody1></tbody1>
                                    <tfoot>
                                        <tr>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                            <td> <strong> Total:</strong> </td>
                                            <td> <strong id="SubTotal1">  </strong> </td>
                                            <td></td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                        <small id="error_SubTotal1" class="form-text error_msg">Atleast add one item</small>
                        <br />
                        <br />
                    </div>

and this is my

js code

$("#addToIe").click(function (e) { e.preventDefault(); var AccountId = $("#Accounts option:selected").val(), AccountsName = $("#Accounts option:selected").text(), qty = $("#Qty1").val(), rate = $("#Rate").val(), narration = $("#Narration").val(), drcr = $("#Drcr").val(), amountt = $("#Amount1").val(), detailsTableBody1 = $("#detailsTable1 tbody1"); var productItem1 = ' ' + AccountId + ' + ' + AccountsName + '' + qty + '' + rate + '' + amountt + '' + narration + ' ' + drcr + ''; detailsTableBody1.append(productItem1); });

]

but when I click on addToIe

it do nothing and not showing any error

please help me

thank

question from:https://stackoverflow.com/questions/65873269/how-to-add-record-in-datatable-in-mvc-view-using-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Actually i was wroing ichanged tbody to tbody1 now I rechanged tbody1 to tbody and it working fine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...