C# 在动态表中添加/编辑注释字段值

C# 在动态表中添加/编辑注释字段值,c#,jquery,html,asp.net-mvc,model-view-controller,C#,Jquery,Html,Asp.net Mvc,Model View Controller,我从SQL表中获取数据,并通过下面的HTML表在局部视图中显示数据: <div class="panel panel-primary"> <h3>Disclosure of Incentives Form</h3> <br /> <table class="table table-condensed table-striped table-bordered" style="width:100%" id="DIFQuestions">

我从SQL表中获取数据,并通过下面的HTML表在局部视图中显示数据:

<div class="panel panel-primary">
<h3>Disclosure of Incentives Form</h3>
<br />
<table class="table table-condensed table-striped table-bordered" style="width:100%" id="DIFQuestions">
    <thead>
        <tr>
            <th> Question</th>
            <th> Outcome</th>
            <th> Comments</th>
        </tr>
    </thead>
    <tbody>
        @For Each d In Model.DIFQuestions
            @<tr>
               <td hidden>@d.ID</td>
               <td width="40%" >@d.Description</td>
               <td width="10%">
                <form id="outcomeRadios">
                    <input type="radio" name="DIFPassFail" id="outcomePass" value="True" /> Pass &nbsp;
                    <input type="radio" name="DIFPassFail" id="outcomeFail" value="Fail" /> Fail
                </form>
              </td>
               <td>
                   <a href="#" class="difcomment" title="Add DIF Information">
                       <span class="fa fa-pencil"></span>
                   </a> &nbsp; Some text here
               </td>
               <td hidden>@d.Order</td>
             </tr>
        Next
    </tbody>
</table>
<br />
<div class="col-md-12">
    <button class="btn btn-success submitDIFAnswers">Submit</button>
</div>
<br>
我希望所有这些都有意义。如果我需要提供更多信息,请告诉我


任何形式的投入都将不胜感激。多谢各位

我通过将
@d.ID
指定为span标记的ID来实现这一点,这样每个
注释都会有一个唯一的ID

然后,我会将id保存到一个全局变量中,每次单击注释行上的铅笔按钮时,我都会重新分配该变量

JQuery如下:

    // open modal to submit dif comment
    $(".difcomment").click(function () {           
        questionID = $(this).parent('td').find('span').prop('id')
        $('#addeditdifcomments').modal('show');
    });

    // submit comment
    $(".submitdifcomment").click(function () {

        var difInfo = $(".difinfo").val();
        var path = "span#" + questionID;

        $(path).text(difInfo);

        $(".difinfo").val('');

        $("#addeditdifcomments").modal('hide');
    });

1) 也许您需要引用一个特定的difcomment元素(例如,为$(“.submitdifcomment”).click()内的元素分配唯一ID和引用,以及2)使用.text(definfo)设置链接文本?您想更新particuler行吗?单击弹出窗口中打开的一行数据并更改数据并保存?@yob谢谢,听起来很有希望。您还可以将ID的值分配并存储在数据属性中:,然后单击将其分配给$(“#addeditfcomments”).attr(“数据ID”),$(this.attr(“数据ID”)),然后从提交中引用它。单击。。。。。
$(document).ready(function () {

    $(".difcomment").click(function () {
        $("#addeditdifcomments").modal('show');
    });


    $(".submitdifcomment").click(function () {

        var difInfo = $(".difinfo").val();

        $(".difcomment").val(difInfo);

        $("#addeditdifcomments").modal('hide');
    });    

});
    // open modal to submit dif comment
    $(".difcomment").click(function () {           
        questionID = $(this).parent('td').find('span').prop('id')
        $('#addeditdifcomments').modal('show');
    });

    // submit comment
    $(".submitdifcomment").click(function () {

        var difInfo = $(".difinfo").val();
        var path = "span#" + questionID;

        $(path).text(difInfo);

        $(".difinfo").val('');

        $("#addeditdifcomments").modal('hide');
    });