3

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 Diego

1 Answer 1

3

Looks 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).

Sign up to request clarification or add additional context in comments.

1 Comment

The Razor editor does have some issues with handling Razor code within JavaScript. This is a known issue and something we're considering for v2, but it'll be like this in v1. As Brian said, despite the green squiggles at design-time, it should still work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.