Format @ Html.Label – MVC

Posted on

Question :

In my page I have one:

@Html.ActionLink(linkText: "Bem Vindo(a) " + User.Identity.GetUserName() + "!", actionName: "Index", controllerName: "RelatorioTagModels1")

What it generates, the “Welcome” page below:


@Html.Label("Bem Vindo(a) " + User.Identity.GetUserName() + "!");

However, I can not format, leave the same as the previous page:

Is it right to use @Html.Label ? for this?
How should I format to visually leave @Html.ActionLink ?


Answer :

The problem is that your CSS has something that formats this line based on the <a> tag of HTML Link to CSS Nested


.Topo a { aqui está o codigo que alinha e deixa branco}

So when you put it without <a href it went without formatting. (it did not even get called the nested css)

3 suggestions:

1. Disable CSS for <A> and change to custom

.Topo a {}

You will replace with:

.MinhaClass{ mesmo código do de cima}

and you’ll call it like this:

@Html.ActionLink(linkText: "Bem Vindo(a) " + User.Identity.GetUserName() + "!", actionName: "Index", controllerName: "RelatorioTagModels1", new with {.class = "MinhaClass" })

* NOTE: For you to find which class you use the ‘inspect’ of your browser, it will show which css it is.

2. Leave with <a> but disable the click

Create the following css:

.disabled {
   pointer-events: none;
   cursor: default;

You just need to call this disable:

@Html.ActionLink (linkText: “Welcome”) + User.Identity.GetUserName () + “!”, actionName: “Index”, controllerName: “ReportTagModels1”, new with {.class=”disabled “})

3. Create a style that corrects the label
something like:

    position: relative;
    top: 20px;
    color: white;

and then you call that LabelNome equal to the above examples

new with {.class = "LabelNome"

NOTE: It may be necessary to change the value 20px


Leave a Reply

Your email address will not be published. Required fields are marked *