Cómo puedo especificar las columnas y filas de un Editor multilínea-Para en ASP.¿MVC?
En ASP.MVC 3, ¿cómo puedo especificar las columnas y filas para una multilínea EditorFor
(textarea)? Estoy usando [UIHint("MultilineText")]
, pero no puedo encontrar ninguna documentación sobre cómo agregar atributos para el área de texto.
HTML deseado:
<textarea cols="40" rows="10"></textarea>
Parte relevante de mi modelo MVC 3:
[UIHint("MultilineText")]
public string Description { get; set; }
Parte relevante de mi Razor cshtml:
<div class="editor-field">
@Html.EditorFor(model => model.Description)
</div>
Lo que estoy recibiendo en Ver Fuente:
<div class="editor-field">
<textarea class="text-box multi-line" id="Description" name="Description"></textarea>
</div>
¿Cómo configuro filas y columnas?
6 answers
Use TextAreaFor
@Html.TextAreaFor(model => model.Description, new { @class = "whatever-class", @cols = 80, @rows = 10 })
O utilice el estilo para la clase multi-line
.
También puedes escribir EditorTemplate para esto.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-06-02 17:32:42
En ASP.NET MVC 5 puedes usar el atributo [DataType(DataType.MultilineText)]
. Mostrará una etiqueta TextArea.
public class MyModel
{
[DataType(DataType.MultilineText)]
public string MyField { get; set; }
}
Luego, en la vista, si necesita especificar las filas, puede hacerlo así:
@Html.EditorFor(model => model.MyField, new { htmlAttributes = new { rows = 10 } })
O simplemente use el TextAreaFor con la sobrecarga correcta:
@Html.TextAreaFor(model => model.MyField, 10, 20, null)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-16 00:16:47
Este también se puede usar con menos esfuerzo creo (pero estoy en MVC 5)
@Html.Description(model => model.Story, 20, 50, new { })
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-22 07:37:29
Una opción parece ser usar CSS para estilizar el textarea
.multi-line { height:5em; width:5em; }
Ver esta entrada en SOo esta.
La respuesta aceptada de Amurra parece implicar que esta clase se agrega automáticamente cuando se usa EditorFor, pero tendría que verificar esto.
EDITAR: Confirmado, lo hace. Así que sí, si quieres usar EditorFor, usar este estilo CSS hace lo que estás buscando.
<textarea class="text-box multi-line" id="StoreSearchCriteria_Location" name="StoreSearchCriteria.Location">
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:34:41
En mvc 5
@Html.EditorFor(x => x.Address,
new {htmlAttributes = new {@class = "form-control",
@placeholder = "Complete Address", @cols = 10, @rows = 10 } })
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-22 13:16:15
En . net VB - podría lograr el control sobre las columnas y filas con lo siguiente en su archivo razor:
@Html.EditorFor(Function(model) model.generalNotes, New With {.htmlAttributes = New With {.class = "someClassIfYouWant", .rows = 5,.cols=6}})
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-09 18:48:32