I want to write a Razor view helper to create the contents of a single line:
@helper Format(obj) { <text> @obj.Title @obj.FormatInnerData() (obj.User != null) { @obj.User.Name } <text> }
But of course I get
Title Inner Data User Name
I have to do now
<text>@obj.Title @obj.FormatInnerData() @(obj.User != null ? obj.User.Name : "")</text>
to output text as a separate line without line breaks, but for many properties this can grow quite a long / unreadable.
In other words, how is it more convenient for me to use Razor to generate text content, and not to mark up the content?
UPD: Ideally, it would be something like
<content>@obj.Title</content> <content>@obj.Format() @obj.User.Name</content>
i.e. only parts between content tags are included in the output stream. Of course, perhaps a simpler syntax like @: instead of <text>.
An example of use is the generation of the contents of a JavaScript string with markup inside or the creation of text files with license data in the format "Key: name (details)" in each line, filled with spaces for grouping.
source share