Razor onchange不承认@variable

时间:2014-06-17 11:43:04

标签: javascript asp.net-mvc razor onchange

 @{
            foreach (CaseCount cc in @Model.CaseCounts)
            {
                <tr>
                    <td>@cc.Country</td>
                    <td>@string.Format("{0:n0}", cc.RegisteredCases)</td>
                    <td>@Html.DropDownList("Reports", new SelectList(@Model.ReportList, "Value", "Text"), new { onchange = "window.location.href='Reports/RenderReport/' + this.value + '/' + @cc.Country;" })</td>
                </tr>
            }
        }

@ cc.Country无法识别。控制器中的操作未被触发:(

如果我删除@ cc.Country或只是将其硬编码,则可以正常工作

1 个答案:

答案 0 :(得分:2)

问题在于你将@ cc.Country作为文本放在引号内。试试这个:

<td>@Html.DropDownList("Reports", new SelectList(@Model.ReportList, "Value", "Text"), new { onchange = "window.location.href='Reports/RenderReport/' + this.value + '/'" + cc.Country + ";" })</td>