I can’t call CSS

Asked

Viewed 129 times

-1

When I use @Html.Editorfor and call css, it doesn’t come in input when I run, even if I take out new { htmlAttributes }

@Html.EditorFor(model => model.Usuario.MATRICULA, new { htmlAttributes = new { @class = "form-control bg-light border-bottom col-md-3" } })

Input when executed:

<input class="text-box single-line" data-val="true" data-val-required="O campo é obrigatório" id="Usuario_MATRICULA" name="Usuario.MATRICULA" type="text" value="">
  • Do any of the answers solve your problem? Need some more details?

2 answers

0

more like you’re calling the css?

the code is on the page or is calling a css file?

it was more practical to call in the head

@Styles.Render("~/Content/css")

or

<style>

</style>

seeing here, I think you have to set the classes correctly, try so:

Model:

public class User_mat
{
    public int User_matId { get; set; }
    [Display(Name="Name")]
    public string User_matName { get; set; }
    public int Age { get; set; }
    public bool isNewlyEnrolled { get; set; }
    public string Password { get; set; }
}


@model User_mat

@Html.TextBox("User_mat", null, new { @class = "form-control bg-light border-bottom col-md-3" }) 

<input type="text" class="text-box single-line"  id="User_mat" name="User_mat"  value="" data-val="true" data-val-required="O campo é obrigatório">

Here explains in detail: https://www.tutorialsteacher.com/mvc/htmlhelper-textbox-textboxfor

  • The code in the view looks like this: @Html.Editorfor(model => model.Usuario.MATRICULA, new { htmlAttributes = new { @class = "form-control bg-light border-bottom col-Md-3" } })

  • But when I give F12 on the page it returns me like this: <input class="text-box single-line" data-val="true" data-val-required="The field is required" id="Usuario_matricula" name="Usuario.MATRICULA" type="text" value="">

  • Does not call the CSS I declare in @Html.Editorfor

0

Exchange the EditorFor for TextBoxFor and the third parameter needs to be a direct object with HTML attributes, not with this property htmlAttributes

@Html.TextBoxFor(model => model.Usuario.MATRICULA, 
                 new { @class = "form-control bg-light border-bottom col-md-3" } )

See working on . NET Fiddle

Browser other questions tagged

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