对于以下代码,我收到错误“当前上下文中不存在名称fn”。错误发生在页面加载和此代码的最后一行:
<script language="javascript" type="text/javascript">
function RunAdvancedSearchClicked() {
var fn = $("#FirstName").val();
var ln = $("#LastName").val();
var ssn = $("#SSN").val();
var doi = $("#DateOfInjury").val();
document.location = '@Url.RouteUrl("ClaimSearch", new { action = "Search", firstName = fn, lastName = ln, dateOfInjury = doi, carrier = ViewBag.Carrier })';
}
</script>
答案 0 :(得分:0)
@ Url.RouteUrl()在客户端执行之前(在服务器上)呈现标记时执行。
您可以在服务器上生成部分链接,然后在javascript中附加值:
var url = '@Url.RouteUrl("ClaimSearch", new { action = "Search", lastName = ln, dateOfInjury = doi, carrier = ViewBag.Carrier })';
document.location = url + '&firstName=' + fn;