简体   繁体   English

多部分视图和javascript

[英]Multiple Partial view and javascript

I am trying to create a paginated report with multiple KPI in a table using MVC, C#,and JavaScript. 我正在尝试使用MVC,C#和JavaScript在一个表中创建具有多个KPI的分页报告。 In order to accomplish this, I created a partial view, with a view model to represent the KPI component. 为了完成此任务,我创建了一个局部视图,该视图具有一个表示KPI组件的视图模型。 I have a small JavaScript file with a document ready function to set the color of the KPI component. 我有一个带有文档准备功能的小JavaScript文件,用于设置KPI组件的颜色。 I load them like this. 我这样加载它们。

<td style="width:30px">
    @Html.Partial("Element", new ElementReadings((decimal)item.NLow,
         (decimal)item.NHigh, (decimal)item.N_PCT))
</td>
<td style="width:30px">
     @Html.Partial("Element", new ElementReadings((decimal)item.NALow,
          (decimal)item.NAHigh, (decimal)item.Na_PCT))
</td>

My problem is the java script only runs on the first row of table. 我的问题是Java脚本仅在表的第一行上运行。 I have tried including the java script file in the partial view (which loads the same file every time according to viewing the page source) but it does not seem to fire except on the first row. 我尝试将Java脚本文件包括在部分视图中(根据查看页面源代码每次都会加载相同的文件),但是除了第一行外,它似乎没有触发。 I even tried to include the java script directly in the cshtml file, again no love. 我什至试图直接将Java脚本包含在cshtml文件中,再次没有爱情。 I am not well versed in web based programming, and looking for any advice. 我不太熟悉基于Web的编程,并且正在寻求任何建议。 My next step in a windows app would be looping through all the controls on the form, getting their name or some property, then run a function against what I found. 我在Windows应用程序中的下一步将是遍历窗体上的所有控件,获取它们的名称或某些属性,然后针对我发现的内容运行一个函数。 Not sure if that is possible with java script and the DOM (?). 不知道使用Java脚本和DOM(?)是否可行。 Guess I will find out. 猜猜我会发现的。 cheers bob 欢呼鲍勃

Edit here is the java script code. 这里是Java脚本代码。

$(document).ready(function () {

var high = $('#high').val();
var low = $('#low').val();
var actualValue = $('#actualValue').val();

if (high > actualValue) {
    $('#HighTextBox').addClass("redBackgroud");

}
else {
    if (low < actualValue) {
        $('#LowTextbox').addClass("redBackgroud");
    }
    else {
        $('#MediumTextbox').addClass("greenBackground");
    }
}

}) })

I think Stephen is correct, and I do not fully understand how html is rendered. 我认为Stephen是正确的,而且我不完全了解html的呈现方式。 I solved the problem on the server side when assigning values to the text boxes. 将值分配给文本框时,我在服务器端解决了该问题。 Thanks for everyone's help and comments. 感谢大家的帮助和评论。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM