Solved

MVC HTML Helper Input Type Number using Safari!

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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 …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

803 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