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

Created 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.

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.

The error I get is "Object reference not set to an instance of an object".
Suggestions?

Viewing all articles
Browse latest Browse all 525

Trending Articles



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