It renders differently because there is no specific template for the type short
or System.Int16
in the private collection of _defaultEditorActions
defined in System.Web.Mvc.Html.TemplateHelpers
. It has only defaults for:
"HiddenInput",
"MultilineText",
"Password",
"Text",
"Collection",
"PhoneNumber",
"Url",
"EmailAddress",
"DateTime",
"Date",
"Time",
typeof(byte).Name,
typeof(sbyte).Name,
typeof(int).Name,
typeof(uint).Name,
typeof(long).Name,
typeof(ulong).Name,
typeof(bool).Name,
typeof(decimal).Name,
typeof(string).Name,
typeof(object).Name,
As you already stated that you have no EditorFor templates there is no otherway for the MVC framework to render a default input tag for you.
To have a specific renderig for a short
datatype add a file Int16
to the EditorTemplates folder under your view folder or under the Shared folder with hte following content:
@model short
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @type = "number" })
This will render short
types from your models as
<input ..... type="number" ... />
Alternatively you could decorate your model property with an UIHint
like so:
[Display(Name = "Start Year")]
[UIHint("Int32")]
public Nullable<short> Start_Year_Period { get; set; }
which basically instructs the TemplateHelper to use the template for the int
type (or System.Int32
in full)