Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用jquery对每个方法进行查询,并从表MVC模型中获取数据_C#_Jquery_Html_Model View Controller - Fatal编程技术网

C# 使用jquery对每个方法进行查询,并从表MVC模型中获取数据

C# 使用jquery对每个方法进行查询,并从表MVC模型中获取数据,c#,jquery,html,model-view-controller,C#,Jquery,Html,Model View Controller,我有一个关于产品和价格的表格,我用MVC模型获取数据,现在我试着在我的图形图表上使用这些数据,但我无法从表格中获取数据。我如何才能获取数据 这是表的HTML代码 <tbody id="table2"> @foreach(var oge in Model) { <tr onclick="method(this)" data-toggle="modal" data-target="#mymodal">

我有一个关于产品和价格的表格,我用MVC模型获取数据,现在我试着在我的图形图表上使用这些数据,但我无法从表格中获取数据。我如何才能获取数据

这是表的HTML代码

   <tbody id="table2">


        @foreach(var oge in Model)
        {
            <tr onclick="method(this)" data-toggle="modal" data-target="#mymodal">
                <td id="product_name">@Html.Raw(oge.product_name)</td>
                <td id="product_price">@Html.Raw(oge.product_price)</td>              
            </tr>
        }

    </tbody>
执行后代码结果为; 0:htmlCell。。。 1:htmlcell。。。 . .
.

如果要使用value,请使用value.innerText访问内容,但我同意上面建议使用$(this).text()的评论


Chance
+value
+$(this).text()
@RoryMcCrossan一切正常,谢谢!当您执行此操作时,
$('td')
jquery将选择所有
td
元素,当您使用
每个
循环通过它时,您将在
值中获得每个
td
元素,当您执行
警报
时,它将只调用
值.toString()
,从而生成
htmlCell
 $("#button").click(function() {          
        $("td").each(function (index,value) {
            alert(index + ": " + value);
        }
        );
    });
   $("#table2 td").each(function (index,value) {
        console.log(index + ": " + value.innerText);
        console.log(index + ": " + $(this).text());
    });