How can I correctly write this MVC razor code to work with my javascript?
I'm using the following code with the开发者_开发技巧 idea of outputting model values into script tags on my page. I'm trying to use the razor view engine. This actually seems to work, but Visual Studio doesn't seem to like it all per the green squiggles throughout my code. How can I correctly do what I'm intending here. Thanks for any help.
@model RepairInformation.Web.ViewModels.MaintenanceViewModel
<div id="tabs"> @{ Html.RenderPartial("_tabs"); } </div>
<script src='@Url.Content("~/Scripts/addressHelper.js")' type="text/javascript"> </script>
<script type="text/javascript">
(function ($) {
$(document).ready(function () {
if (typeof selectedVehicle != 'undefined') {
selectedVehicle = new $repairInfo.Vehicle(@Model.CurrentVehicle.Vid , @Model.CurrentVehicle.Year, '@Model.CurrentVehicle.Make', '@Model.CurrentVehicle.Model');
debugger;
}
});
})(jQuery);
</script>
Please let me know how to do this properly.
Thanks,
~ck in San DiegoLooks good to me. Where are you getting the green squiggles? My guess is that Visual Studio is just having a hard time in the Javascript because of the @Model... in the code (this is not valid Javascript, but it will be fixed once the html is rendered).
精彩评论