Giter Site home page Giter Site logo

Why to use DataType.Email for setting the InputType=Email for Textbox when an Textbox can easily accepts Email Address about mva-introduction-to-aspnet-mvc HOT 3 CLOSED

jongalloway avatar jongalloway commented on June 16, 2024
Why to use DataType.Email for setting the InputType=Email for Textbox when an Textbox can easily accepts Email Address

from mva-introduction-to-aspnet-mvc.

Comments (3)

 avatar commented on June 16, 2024 2

You are definitely right, you could use it without the given attribute. However, if you want to have data validation out of the box, you would want to include that as well.

from mva-introduction-to-aspnet-mvc.

LordScree avatar LordScree commented on June 16, 2024

Hi AnmolRathod1. You are right in that, without the email attribute, input fields will accept email data. However, you could think of it in terms of sets: email input is a subset of general text input. If you know you are collecting just email type data, you would want to narrow the focus. If you are looking for any text input, including email, you would want to leave the attribute off.

One analogy is with fruit, where apple is a subset of fruit:
"I would like a piece of fruit": You could get a banana, an orange, an apple, a pears, etc.
"I would like an apple:" You just get an apple.

It's also worth noting that modern browsers make use of the additional HTML attributes rendered on the page. So you're not just getting the benefit of email validation, but you may also get a more email-focussed on-screen keyboard and other UI benefits when you use the email attribute. Think specifically with tablet PCs and smart phones, where the keyboard is shown on the screen; an email-focussed keyboard may include common domain-name endings (such as .com, .org, etc.) and a prominent "@" symbol.

Finally, you can create your own attributes to do other validation or provide you with client-side hooks for certain fields. If you get into the habit of using the right built-in attributes for the right fields, you will be more likely to add new custom functionality in the Microsoft MVC way, which will make your code more readily usable by others and probably make it easier to develop in the first place.

I hope that helps.

from mva-introduction-to-aspnet-mvc.

AnmolRathod1 avatar AnmolRathod1 commented on June 16, 2024

@LordScree thank you for your help you explained me in much much easier way and yes it helped me a lot

from mva-introduction-to-aspnet-mvc.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.