Open Eilon opened 7 years ago
From @dougbu on November 27, 2016 20:27
@mojtabakaviani what are your expectations exactly?
@ViewBag.Id
inserts the current value into the generated HTML / JavaScript. So, unless that value happened to be a valid literal, I'd expect JavaScript errors in the first example.
From @mojtabakaviani on November 28, 2016 8:31
No any error, just in the first example formatting not working. can not inserts numerical or code without literals.
From @dougbu on November 28, 2016 18:3
Sounds like the system is working as-expected. Or, what special-casing were you requesting here?
Suggest looking at the generated HTML and confirming.
From @mojtabakaviani on November 28, 2016 18:26
I think formatting not support this scenario and must add this feature.
@doug the quotes are needed only for certain data types, e.g. strings. If the id is a numeric type the quotes would be incorrect.
I am able to reproduce the problem in VS2015 U3:
<script>
var value = @ViewBag.Id;
</script>
(Note all the extraneous spaces around the =
sign.)
Expected: The JavaScript code should be better-formatted by trimming the extraneous spaces around the =
sign.
Result: No formatting takes place.
However, if you wrap the @ViewBag.Id
in quotes, i.e. '@ViewBag.Id'
, then repeat, it all works great.
TFS Bug#362028
From @mojtabakaviani on November 27, 2016 8:28
For example some time need insert value to javascript code in cshtml files:
but formatting not working until add quotas:
Copied from original issue: aspnet/Razor#871