For the following code, I’m getting the error “The name fn does not exist in the current context.” The error is happening on page load and on the last line of this code:
<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>
@Url.RouteUrl() is executed when the markup is being rendered (on the server) before the client executes.
You could generate part of the link on the server, then append the value in javascript: