开发者

Html.LabelFor helper in MVC2

开发者 https://www.devze.com 2022-12-10 05:42 出处:网络
I\'m using MVC2, Preview 2. Why is it that when I use: <%= Html.LabelFor(x => x.Nombres) %> <%= Html.Encode(Model.Nombres) %>

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.Labe开发者_如何学JAVAlFor that is producing the extra return.


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.


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".

0

精彩评论

暂无评论...
验证码 换一张
取 消