使用jquery在单击事件中发出

使用jquery在单击事件中发出,jquery,asp.net-mvc,event-handling,Jquery,Asp.net Mvc,Event Handling,我已经实现了MVC应用程序。 代码如下 <table class="table table-striped table-hover" id="mytable"> <thead> <tr > <th> Section Name </th> <th>Section Code </th> <th> Size</th>

我已经实现了MVC应用程序。 代码如下

<table class="table table-striped table-hover" id="mytable">
     <thead>
     <tr >  <th>  Section Name </th>
           <th>Section Code </th>
           <th> Size</th>
           <th> Avg. Length </th>
           <th style="border-right:solid #e8eef4 thick;">Thinkness</th>
           <th> Order Quantity</th>
           <th>Balance Quantity </th>
           <th style="border-right:solid #e8eef4 thick;border-left:solid #e8eef4 thick;"> Available Quantity  </th>
           <th> Supply Quantity</th>
           <th> </th>
     </tr>
    </thead>

<tbody id="tbody">

@foreach (var item in ViewBag.ProductList)

{
    <tr id="tableRow" >
        <td  > @item.SectionName</td>
        <td > @item.SectionCode </td>
        <td > @item.Size </td>
        <td > @item.Length </td>
        <td style="border-right:solid #e8eef4 thick;"> @item.Thickness </td>
        <td > @item.OrderQuantity </td>
        <td > @item.BalanceQuantity </td>
        <td  style="border-right:solid #e8eef4 thick ;border-left:solid #e8eef4 thick;" > @item.AvailableQuantity </td>
        <td ><input id="supplyQuantity" class="supply" type="text" style="width:100px ;height:15px ;margin:1px "  /></td>
        <td  id="editRow" > <a href="#" class="editClass"  style="font-size: 12px; text-decoration: none; margin-right: 10px;">Edit </a> </td>
     </tr>
}

</tbody>
</table>


现在,我的问题是,当我单击
OK
按钮时,
Supply Quantity
列中的值会随着页面刷新而消失。我也希望对剩余记录进行相同的处理。有什么解决方案吗?

您可以在单击功能中使用以下代码行

$('body').on('click', '#btnOk1', function(e) {
    e.preventDefault();
    var url="@Url.Action("DispatchNow")";
    $(location).attr('href', url);
});

$('body').on('click', '#btnCancel1', function(e) {
    e.preventDefault();
    var url="@Url.Action("DispatchNow")";
    $(location).attr('href', url);
});

$('body').on('click', '#btnClose1', function(e) {
    e.preventDefault();
    var url="@Url.Action("DispatchNow")";
    $(location).attr('href', url);
});

您在同一页上多次使用
id
值。这是无效的标记,可能会导致此代码的行为未定义。首先在HTML元素中使用唯一的
id
值,然后再次调试代码。我不知道如何创建动态“id”。你能帮我吗?
$('body').on('click', '#btnOk1', function(e) {
    e.preventDefault();
    var url="@Url.Action("DispatchNow")";
    $(location).attr('href', url);
});

$('body').on('click', '#btnCancel1', function(e) {
    e.preventDefault();
    var url="@Url.Action("DispatchNow")";
    $(location).attr('href', url);
});

$('body').on('click', '#btnClose1', function(e) {
    e.preventDefault();
    var url="@Url.Action("DispatchNow")";
    $(location).attr('href', url);
});