This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
An inline if-statement in an attribute value crashes razor #594
Closed
Description
The following code fails in beta8:
<div class="alert alert-new-arrival @if (Model == null) { <text>hidden</text>}" id="alert-new-arrival" role="alert">
If this is replaced with:
<div class="alert alert-new-arrival @(Model == null ? "hidden" : "") id="alert-new-arrival" role="alert">
it works. The error seen is coming from some generated code. The message is:
An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.
• Not all code paths return a value in lambda expression of type 'Func<TextWriter, Task>'
40. {
41. __tagHelperRunner = __tagHelperRunner ?? new Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperRunner();
42. BeginContext(40, 4, true);
43. WriteLiteral("<div");
44. EndContext();
45. WriteAttribute("class", Tuple.Create(" class=\"", 44), Tuple.Create("\"", 118), Tuple.Create(Tuple.Create("", 52), Tuple.Create("alert", 52), true), Tuple.Create(Tuple.Create(" ", 57), Tuple.Create("alert-new-arrival", 58), true),
46. Tuple.Create(Tuple.Create(" ", 75), Tuple.Create<System.Object, System.Int32>(new Microsoft.AspNet.Mvc.Razor.HelperResult((__razor_attribute_value_writer) => {
47. #line 3 "/Views/Shared/Components/Announcement/Default.cshtml"
48. if (Model == null) {
49.
50. #line default
51. #line hidden
52.
53. BeginContext(104, 6, true);
54. WriteLiteralTo(__razor_attribute_value_writer, "hidden");
55. EndContext();
56. #line 3 "/Views/Shared/Components/Announcement/Default.cshtml"
57. }
58.
59. #line default
60. #line hidden
61.
62. }