Quantcast
Channel: RazorGenerator Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 525

Commented Unassigned: Problem with razor values in html-attributes (mvc4 + 5) [157]

$
0
0
I've tested my code with ASP.NET MVC 3 3.0.20105.1 and it works. I want to upgrade to MVC 4 4.0.40804 but this snippet does not work. Even tried with MVC 5.2.2.

Tested with RazorGenerator 2.2.3

This is some simplified example-code from a helper.cshtml:
```
@using System
@* Generator: MvcHelper *@

@functions
{
public HelperResult Message(string msg)
{
return MessageHtml(msg);
}
}

@helper MessageHtml(string msg)
{
<h1>@msg</h1>
<h1 class="@msg">@msg</h1>
}
```

Then I use it in Index.cshtml:
```
@{
var h = new MvcApplication1.Helpers.Helper();
}
@h.Message("hello")
```

The first h1 will work but the other one wont (because of the class-attribute). I need to be able to create functions and reuseable helpers within one cshtml-file.

I get a basic null-reference error ("Object reference not set to an instance of an object").
Suggestions?
Comments: What's at line 14 of Helper.cshtml? Can you debug it to see if everything looks normal? Also, are you sure that the issue doesn't happen if you don't precompile your view?

Viewing all articles
Browse latest Browse all 525

Trending Articles



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