Solved

MVC HTML Helper Input Type Number using Safari!

Posted on 2014-03-13
3
2,531 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

861 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