单击按钮后在范围文本中插入模型字符串



使用Razor很容易在html中显示列表的值:

<div id="collapse1" style="display:none">
@{
    foreach (var i in Model)
    {
        <text> <strong>::: @i.City, @i.Country :::</strong> </text>
        <p style="margin-bottom:0px"></p>
        foreach (var h in i.Weather)
        {
            {
                <div id="MyDiv2">
                    <strong><small>@DateTime.Now.AddDays(count).ToString("dd/MM/yy")</small></strong>
                    <p style="margin-bottom:0px"></p>
                    <text><small>Max: @i.MaxTemp.ElementAt(@count)°</small></text>
                    <p style="margin-bottom:0px"></p>
                    <text><small>Min: @i.MinTemp.ElementAt(@count)°</small></text>
                    <span id="MyTest">the min temp: @i.MinTemp.ElementAt(0) </span>
                </div>
            }
            count++;
        }
    }
}
</div>

是的,小菜一碟。但是要知道,想象一下,我想在单击按钮后更改范围MyTest中的文本,以便它具有:"最大温度:@i.MaxTemp.ElementAt(0)"。

我的问题是我必须混合jQuery(用于按钮)和剃刀(以获取maxtemp值)。任何帮助/提示都非常感谢!

<div id="collapse1" style="display:none">
@{
    int mycounter=0;
    foreach (var i in Model)
    {
        <text> <strong>::: @i.City, @i.Country :::</strong> </text>
        <p style="margin-bottom:0px"></p>
        foreach (var h in i.Weather)
        {
            {
                <div id="MyDiv2">
                    <strong><small>@DateTime.Now.AddDays(count).ToString("dd/MM/yy")</small></strong>
                    <p style="margin-bottom:0px"></p>
                    <text><small>Max: @i.MaxTemp.ElementAt(@count)°</small></text>
                    <p style="margin-bottom:0px"></p>
                    <text><small>Min: @i.MinTemp.ElementAt(@count)°</small></text>
                    <span maxtemp=' @i.MaxTemp.ElementAt(0)' id="MyTest">the min temp: @i.MinTemp.ElementAt(0) </span>
                </div>
            }
            count++;
        }
    }
}
</div>
$('#MyTest').on('click',function(){
$(this).text($(this).attr('maxtemp'));
}):

最新更新