George Great
George Great

Reputation: 253

Int input type in MVC5

I have a textbox that allows only integers. I recently created a page in MVC 3 that has a similar textbox with this input type:

@Html.TextBoxFor(model => model.Minute,new {style="width: 250px", @type = "number" })

And now I tried to recreate the textbox in MVC 5, but this input type doesn't seem to work. I don't want to make it in javascrip, or jquery or in C# code. Is there any syntax for it in MVC 5?

Upvotes: 1

Views: 3629

Answers (2)

K D
K D

Reputation: 5989

If you are using MVC 5.1 or higher , try to make it like following and check if it works

@Html.TextBoxFor(model => model.Minute,new {style="width: 250px", type = "number" })

remove the @ and try

Upvotes: 2

DHARMRAJ THAKUR
DHARMRAJ THAKUR

Reputation: 82

Do not make hard code in html helper,

Just Open your Model and go to that property and use DataAnnotation Class Features.

{
    [DataType(DataType.Number)]
    public int? sessionDurationMinutes { get; set; }
}

Your Textbox will be reduced to...

@Html.TextBoxFor(model => model.sessionDurationMinutes, new {style="width: 250px"})

Upvotes: 1

Related Questions