How do I specify the columns and rows of a multiline Editor-For in ASP.MVC?

后端 未结 7 1987
梦毁少年i
梦毁少年i 2020-12-08 12:42

In ASP.MVC 3, how do I specify the columns and rows for a multiline EditorFor (textarea)? I am using [UIHint(\"MultilineText\")], but can\'t find a

相关标签:
7条回答
  • 2020-12-08 13:12

    In ASP.NET MVC 5 you could use the [DataType(DataType.MultilineText)] attribute. It will render a TextArea tag.

    public class MyModel
    {
        [DataType(DataType.MultilineText)]
        public string MyField { get; set; }
    }
    

    Then in the view if you need to specify the rows you can do it like this:

    @Html.EditorFor(model => model.MyField, new { htmlAttributes = new { rows = 10 } })
    

    Or just use the TextAreaFor with the right overload:

    @Html.TextAreaFor(model => model.MyField, 10, 20, null)
    
    0 讨论(0)
  • 2020-12-08 13:13

    @Html.TextArea("txtNotes", "", 4, 0, new { @class = "k-textbox", style = "width: 100%; height: 100%;" })

    0 讨论(0)
  • 2020-12-08 13:16

    Use TextAreaFor

    @Html.TextAreaFor(model => model.Description, new { @class = "whatever-class", @cols = 80, @rows = 10 })
    

    or use style for multi-line class.

    You could also write EditorTemplate for this.

    0 讨论(0)
  • 2020-12-08 13:17

    in mvc 5

                  @Html.EditorFor(x => x.Address, 
                  new {htmlAttributes = new {@class = "form-control", 
                       @placeholder = "Complete Address", @cols = 10, @rows = 10 } })
    
    0 讨论(0)
  • 2020-12-08 13:20

    This one can also be used with less effort I believe (but I am in MVC 5)

    @Html.Description(model => model.Story, 20, 50, new { })
    

    0 讨论(0)
  • 2020-12-08 13:36

    One option seems to be using CSS to style the textarea

    .multi-line { height:5em; width:5em; }
    

    See this entry on SO or this one.

    Amurra's accepted answer seems to imply this class is added automatically when using EditorFor but you'd have to verify this.

    EDIT: Confirmed, it does. So yes, if you want to use EditorFor, using this CSS style does what you're looking for.

    <textarea class="text-box multi-line" id="StoreSearchCriteria_Location" name="StoreSearchCriteria.Location">
    
    0 讨论(0)
提交回复
热议问题