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: It's the h1 with the attribute at 14. This code works with the older version of mvc and also if I call the helper directly and remove the function. The problem is when I call a the function, that calls the helper, that contains an element with an attribute, with a razor-value. A bad solution is to move the functions to a separate cs-file and then call the helpers from there

Viewing all articles
Browse latest Browse all 525

Trending Articles



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