Solved

MVC HTML Helper Input Type Number using Safari!

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…

738 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