How do I render unbreakable text with HTML helpers - asp.net-mvc

I use #html helper to render components in asp.net .cshtml view
#Html.Label((string)ViewBag.SomeExpression, (string)ViewBag.SomeText)
The problem is - output label has breakable text inside. How do I make output spaces unbreakable (&nbsp) for ViewBag.SomeText value?

Related

How to Render Line Numbers with Document in AvalonEdit?

Is there a way to render line numbers in the left margin along with the AvalonEdit TextEditor document?
if used as wpf controller, add
ShowLineNumbers="True"
to the avalonedit tag

How to display localized text rendered from javascript in a razor cshtml view

We display a tooltip on mouse enter that gives a hint about the field over which they hover. We would like to localize that text. All other localized text in the view is localized using resource bundles and are loaded using something like #Localizer"My text"). But on mouse enter the text is rendered by the js. SO how does one localize that in a razor view.

How to render my external html file inside the div element in MVC?

I have tried #Html.Raw(Model) but it renders only the plain html. The css styles are not embedded in view.
How to render a Html file inside the div with the css styles?
Thanks in advance!
Try something like that, but not sure whether it's included the css.
#Html.Raw(File.ReadAllText(Server.MapPath("~/Index.html")))
Suggest you to create the partial view and call it in your view page.
#Html.Partial("~/Views/Shared/_Index")

text rendered in partial view still encoded

I have text in my database that is html encoded.
In order to display it on a normal view, I use the technique described here -
#Html.Raw(encodedHtmlString)
and it displays as expected.
However, when I do the same thing in a partial view, and then render that view with .Partial or .RenderPartial, the text is still encoded, even though the partial view renders it with #Html.Raw().
How do you prevent the parent view from encoding text rendered in a partial view?
Try this instead:
#Html.Raw(Html.Partial("your view name"))
Hope this will help !!

How do I allow Multi-line content in a rails text_area field?

How would I go about allowing users to input multi-line text in a text_area form field?
Currently anytime content is entered in the text areathe line breaks are removed... They are retained when I edit the content... So, maybe it's in the show view that the breaks are being removed?
I've found a few things that indicate that I'd need to implement a WYSIWYG editor, but I'd prefer to avoid that if possible.
Any suggestions?
UPDATE: So, it looks like rails saves the content with line breaks, and I can add .html_safe to the field in the show view (i.e. <%= #post.post.html_safe %>). Now it will present content with basic html (e.g. <br>, <b>, etc...) but still doesn't present the line breaks in the content (i.e. when I press enter for a new line) that are saved by rails and I can view when I'm editing the content.
Linebreaks are not rendered in HTML. You will want to use something like simple_format or wraptext on your content as you echo it out to convert newlines to <br> or <p> tags.
<%=simple_format(#post.post).html_safe %>
or
<%=Wraptext::Parser.new(#post.post).to_html.html_safe %>

Resources