Is it from this line you get the \r\n? @Html.Partial(FieldViewResolver.GetFieldView(Model.FormId, f.FieldTypeName, f.Caption), f) - if so try adding Replace in the end like @Html.Partial(FieldViewResolver.GetFieldView(Model.FormId, f.FieldTypeName, f.Caption), f).Replace("\r\n","");
Generally, in the most simple fashion, linebreaking sequences are replaced with equivalent HTML linebreak elements (as opposed to no space at all), so, say, a <br/> tag.
MvcHtmlString obviously doesn't contain all methods of string, yet is a glorified representation of a string, so you can get the literal by calling .ToString() to resolve the error, then do a replace on the result, such that:
Tried the javascript approach, which seems hacky at best, but that requires you to wrap the input field in a container, like a div, which seems to break the conditional-field-logic-stuff, at least in my code.
So, does anybody have an idea on how to restructure the view to get rid of the whitespaces?
Razor render White-space after html element
Hi there,
I have this simple form (via razor in contour 3):
and for some reason I get \r\n in the html just after the <div class="info">.
Any idea on how to get rid of it?
Thanks
mkariti
Hi mkariti
Is it from this line you get the \r\n? @Html.Partial(FieldViewResolver.GetFieldView(Model.FormId, f.FieldTypeName, f.Caption), f) - if so try adding Replace in the end like @Html.Partial(FieldViewResolver.GetFieldView(Model.FormId, f.FieldTypeName, f.Caption), f).Replace("\r\n","");
Hope this helps.
/Jan
Hi Jan,
Thanks but the problem persist.
I can seems to refference the System.Web.Mvc.dll but not use it from the razor file?!
Also, I get the following error:
System.Web.Mvc.MvcHtmlString' does not contain a definition for 'Replace'
Tried to string it and htmled it again but still get the \r\n
Any other idea?
Cheers
mkariti
Any help with this one will much appriciated.
Generally, in the most simple fashion, linebreaking sequences are replaced with equivalent HTML linebreak elements (as opposed to no space at all), so, say, a <br/> tag.
MvcHtmlString obviously doesn't contain all methods of string, yet is a glorified representation of a string, so you can get the literal by calling .ToString() to resolve the error, then do a replace on the result, such that:
@Html.Partial(FieldViewResolver.GetFieldView(Model.FormId, f.FieldTypeName, f.Caption), f).ToString().Replace("\r\n","<br/>");
Hi Thomas,
Thanks for your reply.
The problem is that now your solution will be rendered as string rather than HTML.
If you will try to convert it back to HTML the whitespace/br will be inserted again.
I managed to do the trick with jquery but I would prefer to nail it down in the rezor.
Cheers
mkariti
Use @Html.Raw to output the resulting HTML literal.
Thanks Thomas,
But still same prob.
Comment author was deleted
Unfortunalty the whitespace is due to a bug in the razor view engine http://forums.asp.net/p/1618460/4149182.aspx if you restructure the view you can get rid of it
Thanks Tim
Hi mkariti,
I've a similar problem. How did you exactly solve it? Changing the way you call the partial view render?
Regards
Matteo
Hi joyefox,
In my case I had to find a quick and easy solution so I just used jquery to remove it:
$('.info').each(function (index) {
$(this).html($.trim($(this).html()));
});
Not elegant as reconstructing the view but did the trick.
Regards,
mkariti
Tried the javascript approach, which seems hacky at best, but that requires you to wrap the input field in a container, like a div, which seems to break the conditional-field-logic-stuff, at least in my code.
So, does anybody have an idea on how to restructure the view to get rid of the whitespaces?
Comment author was deleted
Pushed a workaround in 3.0.10 WIP that should fix the whitespace issues
The way i found easiest is to open the files in Notepad++, change the encoding to UTF-8, without BOM and save them.
100% of allt the times, it works every time.
is working on a reply...