Format @Html.Label - MVC

Asked

Viewed 607 times

4

On my page I have one:

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

Which generates, the "Welcome" page below:

inserir a descrição da imagem aqui

However, I don’t want it to be a link, I only wanted one Label, so I switched the code to:

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

However, I cannot format, leave the same as the previous page:

inserir a descrição da imagem aqui

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

  • Good evening my dear, this training can be done in CSS?

  • @Anselmo yes, I’m working with CSS, but I’ve tried to find this configuration of ActionLink to switch to the Label but without success

  • I may be wrong but surely you must have a class or ID that formats the action.link, searches and changes to . label

  • 1

    By default mvc uses bootstrap. In boostrap css it should have something like: navbar > a and then the effect of keeping the position there in the middle... When you change to label it loses. Inspect the element when you have the link and check which class is active in css, and create a class for you using the label.

  • @Thomaserichpimentel inspects the html page generated by ActionLink and note which css classes are included in the element, then see the method documentation .Label() how to pass an additional css class to be included in the element and put the previously noted classes in Actionlink.

1 answer

2


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

Example:

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

So when you put it without the <a href it was left without formatting. (it was not even called the nested css)

3 suggestions:


1. Disable the CSS for <A> and switch to something custom Ex:

.Topo a {}

you will replace with:

.MinhaClass{ mesmo código do de cima}

and you’ll call it so:

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

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


2. Leave with <a> but disable the click

Create the following css:

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

Just call that disable:

@Html.Actionlink(linkText: "Welcome(a) " + User.Identity.Getusername() + "!" , actionName: "Index", controllerName: "Reportariotagmodels1", new with {.class = "disabled" })


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

.LabelNome{
    position: relative;
    top: 20px;
    color: white;
}

and then you call this Labelname equal to the examples above

new with {.class = "LabelNome"

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.