Solved

MVC HTML Helper Input Type Number using Safari!

Posted on 2014-03-13
3
2,571 Views
Last Modified: 2014-03-20
I'm understanding that a Numeric pad instead of the default keyboard will open in Safari on iPhone if I code like:
           <input id="amount" type="number" />

I would like to know if this is possible in MVC4 like so:
          @Html.EditorFor(m => m.Expense.Amount, new { type = "number" })

I've also read about including the DataType attribute like so. Just don't know if it will trigger the numeric pad in Safari on iPhone:

          [DataType(DataType.Number)]
          public decimal Amount { get; set; }
0
Comment
Question by:WorknHardr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 500 total points
ID: 39927834
I'm not entirely sure what you're asking here. If specifying type="number" on the <input> element causes the numeric keypad then it doesn't matter what the server-side technology is, it only matter what gets generated. This doesn't seem all that hard to test, I just did it in about five minutes by creating a new MVC application. Using your code I got:

<input class="text-box single-line" data-val="true" data-val-number="The field Amount must be a number." data-val-required="The Amount field is required." id="Expense_Amount" name="Expense.Amount" type="text" value="0.00" />

So the answer would appear to be "no, it won't generate the HTML you want because the type attribute is "text."

I then tried using:

@Html.TextBoxFor( m => m.Expense.Amount, new { type = "number" } )

Open in new window


When I did that the result was:

<input data-val="true" data-val-number="The field Amount must be a number." data-val-required="The Amount field is required." id="Expense_Amount" name="Expense.Amount" type="number" value="0" />

So it would appear that using TextBoxFor will generate what you want.

Frankly, it took me longer to type this answer than to put together the test that got me the results.
0
 

Author Comment

by:WorknHardr
ID: 39927909
I'm using Html.EditorFor
0
 

Author Closing Comment

by:WorknHardr
ID: 39943439
thx
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question