troubleshooting Question

HTML5 Form - MVC - require email format

Avatar of RBS
RBS asked on
Web ApplicationsMicrosoft DevelopmentC#
2 Comments1 Solution380 ViewsLast Modified:
Hi:
I have an MVC5 app in which I create a ViewModel to populate a form.  I would like to require that one of the fields have a valid email address.  I have decorated the relevant field as follows in the ViewModel:


[Required, MaxLength(100), DataType(DataType.EmailAddress), Display(Name="Email From")]
        public string EmailFrom { get; set; }

The required field is written as follows in the chtml page:

                <div class="control-group">
                    @Html.LabelFor(model => model.EmailFrom, new { @class = "control-label" })
                    @Html.TextBoxFor(model => model.EmailFrom, null, new { @class = "help-inline form-control" })
                    @Html.ValidationMessageFor(model => model.EmailFrom, null, new { @class = "help-inline" })
                </div>

The code works as far as requiring something to be entered - but lets me enter a non-valid email field.  any help in fixing this would be greatly appreciated.

RBS
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros