0

For a C# MVC 5 application we have the following partial view:

@using some.using.here
@using some.using.here
@using some.using.here

@{
    var treeItem = TempData["SELECTED_TREEITEM"] as ITreeItem;
    string path = treeItem.GetIdPath(TempData.GetParentId());
    User user = Session["somesessionkey"] as User;
}

<!-- Selected item from URL -->

@if (treeItem != null)
{
    <input type="hidden" id="routeData" data-key="@treeItem.Key" data-treepath="@path" data-area="@TempData["SELECTED_AREA"]" data-mode="@TempData["SELECTED_MODE"]">
}
<input type="hidden" id="defaultAsset" data-default="@(user != null ? (user.DefaultAsset != null ? methodcall(value).ToString() : string.Empty) : string.Empty)" />
<input type="hidden" id="newPeriodHrs" data-newperiodhrs="@(user != null ? user.NewPeriodHrs : 48)" />

However, no matter what I do, Resharper keeps complaining with the following message:

Views\Shared\_RouteData.cshtml:18 Closing brace expected

To save you from counting, line 18 is at the end of the file.

Contrary to what Resharper might suggest, the whole project compiles and runs fine. But is there still some kind of syntax issue I'm missing? Or is Resharper just plain wrong in this case? I'm running Resharper 8.2 (C# edition).

(please excuse my poor attempt at removing sensitive information from the code, I left all braces and such intact)

Vincent
  • 1,459
  • 15
  • 37
  • Does the code compile? Can you view the page? A missing `}` in Razor will result in a YSOD. If you can view the page, Resharper is wrong. If you can't, you'll probably see a similar error on the exception message – Panagiotis Kanavos Jan 09 '15 at 10:36
  • I'll bet though that this `"@TempData["SELECTED_AREA"]"` is causing the problem - double quotes inside a string – Panagiotis Kanavos Jan 09 '15 at 10:38
  • The code compiles and runs fine (as already described above). The `"@TempData["SELECTED_AREA"]"` actually works just fine, causes no error on the multitude of other pages it's used on. – Vincent Jan 09 '15 at 10:52

1 Answers1

1

Turns out the solution is really sneaky, a single slash is missing in this piece:

@if (treeItem != null)
{
    <input type="hidden" id="routeData" data-key="@treeItem.Key" data-treepath="@path" data-area="@TempData["SELECTED_AREA"]" data-mode="@TempData["SELECTED_MODE"]">
}

It should look like this: data-mode="@TempData["SELECTED_MODE"]" />

Vincent
  • 1,459
  • 15
  • 37
  • It's still a Resharper bug, as it confused a valid HTML tag with server-side code. An `input` element is a void element and does not require an end slash in HTML5. Perhaps it's fixed in R9 – Panagiotis Kanavos Jan 09 '15 at 11:04