Using #pragma statement in Razor View

2019-07-17 21:50发布

问题:

We have some files with the jQuery vsDoc includes like this for syntax help;

@if (false)
{
    <script src="@Url.Content("~/Scripts/jquery.validate-vsdoc.js")" type="text/javascript"></script>
}

And it generates some annoying compiler warnings about unreachable code, I would like to wrap that statement with a #prama warning but I cant figure out the syntax in Razor.

Thanks!

回答1:

@{ #pragma warning disable } 
@if (false)
{
    <script src="@Url.Content("~/Scripts/jquery.validate-vsdoc.js")" type="text/javascript"> </script>
}
@{ #pragma warning restore }

Works for me



回答2:

I think this should work...

@{#pragma warning disable}