Reputation: 26141
I'm using the Razor view engine with MVC3 RC1 and Razor, and running through the NerdDinner tutorial with it.
I have a partial view that contains some markup followed by this snippet of Javascript:
<script type="text/javascript">
$(document).ready(function () {
$("#Address").blur(function (evt) {
$("#Latitude").val("");
$("#Longitude").val("");
var address = jQuery.trim($("#Address").val());
if (address.length < 1)
return;
FindAddressOnMap(address);
});
});
</script>
I get a Parser error on the "if (address.length < 1)
": "Tag is missing a name. All tags must contain a valid tag name after the '<' character".
I've tried using <text></text>
around the block of code, but I still get the same error. Since there isn't much official documentation available yet for Razor, I'm hoping someone will be able to tell me what I'm doing wrong and how to fix it.
Upvotes: 4
Views: 381
Reputation: 26689
The problem looks to be that you probably have your script tag within a code block @{}
.
Checking the parser and attempting several different work arounds if you just remove the whitespace you'll be fine. if (address.length<1)
Strange though that it works in a custom app that uses the razor parser outside of MVC. This will probably take some work to find the real cause. Actually, some more detailed testing reveals that it does cause an error in the parser too - I just don't do anything special which I want to say thanks for pointing this out. It's something I'll have to fix.
The parser went through some changes between 2 and 3 so this is probably a bug introduced with those changes.
Upvotes: 4