Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net MVC5 with Bootstrap EditorFor size

I have some modifications to bring to a form which use EditorFor (and using MVC5) and I can't find the way of setting the size of the text box ... I tried the hard way with:

@Html.EditorFor(model => model.Nom, new{@style="width:400px"})

But this did not work.. Is there an easy way?

like image 441
Alain BUFERNE Avatar asked Feb 23 '14 22:02

Alain BUFERNE


2 Answers

In MVC up to version 5, EditorFor does not allow you to specify html elements in that way. It can only be used in non-editor contexts, like TextBoxFor, etc...

In MVC 5.1 they added the ability to specify html attributes in Editor templates, and you can now do this:

@Html.EditorFor(model => model, new { htmlAttributes = new { @class = "form-control" }, })
like image 152
Erik Funkenbusch Avatar answered Sep 19 '22 15:09

Erik Funkenbusch


Using MVC 5 - You need to use [DataType(DataType.MultilineText)] attribute on your view model ejm:

using System.ComponentModel.DataAnnotations;

public class Requests
{

    [Display(Name = "Id")]
    public int RequestId { get; set; }

    [DataType(DataType.MultilineText)]
    public string Comments { get; set; }
}
like image 41
William Ballesteros Avatar answered Sep 18 '22 15:09

William Ballesteros