c# - 将参数从 C# 传递到 Jquery

标签 c# jquery

如何将参数从 C# 传递到 部分,而不是使用不同的值对其进行硬编码。

<div class="property-container">
      <input class="progress-value" type="hidden" value="17" />           
        <div class="property-title">Test</div> 
        <div class="property-progress"></div>
    </div>    

    <div class="property-container">
        <input class="progress-value" type="hidden" value="32" />
        <div class="property-title">Test 2</div> 
        <div class="property-progress"></div>
    </div>    

    <div class="property-container">
        <input class="progress-value" type="hidden" value="24" />
        <div class="property-title">Test 3</div> 
        <div class="property-progress"></div>
    </div>    

        <script type="text/javascript" >/
            $(function () {
                // loop through each 'container'
                $(".property-container").each(function () {


                    // get the value that was rendered from the model
                    var progress = parseInt($(this).children(".progress-value").val());

                    // create the progress bar with the value
                    $(this).children(".property-progress").progressbar({ value: progress });

                });
            });

        </script>

最佳答案

来自您的评论

<input class="progress-value" type="hidden" value="17" id="Test" /> 
In c# I tried, Test.Value = "20";

如果您想访问代码隐藏中的隐藏字段,您应该有一个 runat="server"

<input class="progress-value" runat="server" type="hidden" value="17" id="Test" /> 

 //& then in C# set it like this..

 Test.Value = "20";

jQuery中,获取隐藏字段的值

$('.progress-value').val()

关于c# - 将参数从 C# 传递到 Jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18990207/

相关文章:

c# - UpdatePanel 中的图像在 Firefox 中不起作用

jquery - 复杂的 html 老年人和父选择器在任何浏览器中都不起作用 - jquery

c# - 仅从 Azure Active Directory 检索已启用的帐户

javascript - net::ERR_ABORTED 404(未找到)

javascript - jquery 加载特定页面/查询字符串

php - TCPDF 不格式化

javascript - 如何从 ASP.NET MVC 4 Controller 捕获 JSON 结果?

C# Readonly List 线程同步

c# - 具有动态属性的 ASP.net MVC3 模型验证

c# - 文件作为附件发送后被锁定