Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Closed Issue: Compilation issue with helper function parameters incorrectly prefixed with an "@" symbol. [1498]

$
0
0
Ported from : https://aspnet.codeplex.com/workitem/10325

Came across an issue with MVC4 regarding helper functions and parameters that incorrectly have an "@" symbol specified.

The helper code to reproduce the issue looks like this:

```
@helper ThisIsAHelper(string input1){
string aWrongVariable = @input1; //note the @ symbol here
if (!string.IsNullOrWhiteSpace(aWrongVariable))
{

}
<div>got it</div>
}

```

The view compilation engine will report this:

_Compilation Error_

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1513: } expected

Source Error:


Line 4: {
Line 5:
Line 6: }
Line 7: <div>got it</div>
Line 8: }

Source File: c:\Users\me\documents\visual studio 2012\projects\mvcapplication1\mvcapplication1\App_Code\TheHelper.cshtml Line: 6

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

This worked perfectly fine under MVC3, and while it wasn't correct code, it would be nice if the tooling would report the actual issue instead of incorrectly stating a problem with a missing closing brace.

Thanks,
Ryan


__NOTE__(Pranav debugged this and following are his comments):
The issue seems to be that the parser does not generate a closing brace:

```
public System.Web.WebPages.HelperResult ThisIsAHelper(string input1) {
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {
string aWrongVariable = @input1; //note the @ symbol here
if (!string.IsNullOrWhiteSpace(aWrongVariable)) {
WriteLiteralTo(__razor_helper_writer, "<div>");
WriteLiteralTo(__razor_helper_writer, aWrongVariable);
WriteLiteralTo(__razor_helper_writer, "</div>");
} //<--------------This brace is missing in the generated code when the input has a @ symbol.
});
}

```
Comments: Duplicate of https://aspnetwebstack.codeplex.com/workitem/587.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>