简体   繁体   English

ASP.NET MVC jQuery HTML5数据属性

[英]ASP.NET MVC jQuery HTML5 data attribute

I have three .cshtml files: _ProductSelection.cstml -> this defines the html table 我有三个.cshtml文件:_ProductSelection.cstml->这定义了html表

@model List<..Rate>
<table id="productgrid">
 <thead>
...
</thead>
<tbody>
     @Html.Partial("_ProductRows", Model)
</tbody>
</table>

_ProductRows.cshtml-> this has some attributes added to each tr and td _ProductRows.cshtml->这会将一些属性添加到每个tr和td

    @if (Model != null && Model.Count > 0)
    {
        foreach (var rate in Model)
        {
            <tr class="@(rate.IsSelected ? "selected" : "")" data-base="@rate.BaseCharge" data-planname="@rate.PlanName" >
...

ProductSelection.cshtml->actual view call from MVC controller: MVC控制器发出的ProductSelection.cshtml-> actual view调用:

    ....
     @Html.Partial("_ProductSelection", Model.Rates)
    ...
    @section scripts {
       ..
        var table = $('#productgrid'),
          tbody = table.find('tbody'),
       ...

     $(function () {
....
     tbody.find('tr').each(function (index, elem) {
                    var self = $(elem),
                        base = parseFloat(self.attr('data-base')),
         .....

This is working code I can access all the data attribute in productSelection.cshtml, which are set in tr tag of _ProductRows.cshtml file. 这是工作代码,我可以访问productSelection.cshtml中的所有data属性,这些属性在_ProductRows.cshtml文件的tr标签中设置。 eg data-base, data-planname 例如数据库,数据计划名称

The problem is: I added some more data attribute to _ProductRows tr tag, but new data attributes are not visible in ProductSelection.cshtml, when i debug in google chrome and check value of elem it only has data attributes define before, newly added attribute in not in 'attribute' list of elem. 问题是:我在_ProductRows tr标记中添加了更多数据属性,但是在ProductSelection.cshtml中看不到新的数据属性,当我在google chrome中调试并检查elem的值时,它仅具有之前定义的数据属性,而在不在元素的“属性”列表中。 In bellow example i don't see newly added data-credit. 在下面的示例中,我看不到新添加的数据信用。

<tr class="@(rate.IsSelected ? "selected" : "")" data-base="@rate.BaseCharge" data-planname="@rate.PlanName" data-credit="@rate.Credit" >

I added almost 20 more data attribute, none of them are visible while debugging in chrome. 我增加了将近20个数据属性,在chrome中调试时它们都不可见。 in Rate model I added all these new fields and populated it from values from database. 在费率模型中,我添加了所有这些新字段,并从数据库中的值填充了它。

thank you everyone for response. 谢谢大家的回应。

I found out the reason why new attributes are not appearing in "elem". 我找出了新属性未出现在“元素”中的原因。

on ProductSelection.cshtml there is one more function which added attributes to tr tag, which overwrites the attributes added in _ProductRows.cshtml. 在ProductSelection.cshtml上,还有一个函数将属性添加到tr标签,该函数将覆盖_ProductRows.cshtml中添加的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET 从 MVC 模型数据渲染 HTML5 画布 - ASP.NET Render HTML5 Canvas from MVC Model Data 带有HTML5的Entity Framework脱机的ASP.NET MVC 4 - ASP.NET MVC 4 with Entity Framework offline with HTML5 动态生成 HTML 控件并在 ASP.NET Core MVC 中使用 jQuery 更改 ID 属性 - Dynamically generate HTML control and change the ID attribute with jQuery in ASP.NET Core MVC ASP.NET MVC / Jquery Unobtrusive Ajax,在返回html数据后尝试检查元素是否加载了Jquery - ASP.NET MVC / Jquery Unobtrusive Ajax, trying to check if element is loaded with Jquery after the html data is returned 使用jQuery“this”的HTML5数据属性 - HTML5 data attribute with jQuery “this” 在ASP.NET MVC 5中使用jQuery AJAX在HTML表中不填充Json数据 - Json data is not populat in html table using jQuery ajax in asp.net mvc 5 C#ASP.NET MVC jQuery .html()函数无法使用DevExpress图表数据 - C# ASP.NET MVC jQuery .html() function not working with DevExpress chart data 我们如何使用Jquery和ASP.NET MVC 4复杂模型数据设置HTML元素的值 - How do we set the value of an HTML element using Jquery and ASP.NET MVC 4 complex model data 从HTML表ASP.net MVC获取使用jQuery添加的数据 - Get data added with jQuery from HTML table ASP.net MVC ASP.NET到HTML5 localStorage - ASP.NET to HTML5 localStorage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM