Question

I'm using MVC2, Preview 2. Why is it that when I use:

        <%= Html.LabelFor(x => x.Nombres) %>
        <%= Html.Encode(Model.Nombres) %>

It outputs:

Nombre:
Sr. Fulano de Tal

But when I use:

        Nombres:
        <%= Html.Encode(Model.Nombres) %>

it outputs:

Nombre: Sr. Fulano de Tal

I don't want the return after the label. Is it my CSS that is ruining things, or is it the HTML.LabelFor that is producing the extra return.

Was it helpful?

Solution

This is really hard to answer. Could do with seeing the actual html markup it is producing. I suspect the labels are either floated or display:block in the css.

OTHER TIPS

View Source will help you know what the right answer is here. What is the HTML generated in each case?

I suspect that what's happening here is that the HTML element generated by Html.LabelFor is defined, in your CSS, as a block element, meaning that subsequent content will start on a new line. If this is what's happening, you can change the CSS for those elements to use display:inline; and they should show up on the same line as your field's value. You can also use the float CSS attribute to generate the same effect, but floats are generally harder to work with than display:inline.

The HTML output for your case should be something like: <label for="Nombres">Nombre</label>. No <br/> is rendered, so the only answer should lie in the CSS, like Justin said. Look for css styles attached to "label" elements, or not so probable, something related to "Nombres".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top