Wrox Programmer Forums
|
BOOK: Beginning ASP.NET Web Pages with WebMatrix
This is the forum to discuss the Wrox book Beginning ASP.NET Web Pages with WebMatrix by Mike Brind, Imar Spaanjaars ; ISBN: 978-1-1180-5048-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Web Pages with WebMatrix section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 18th, 2013, 05:32 PM
Registered User
 
Join Date: Dec 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 4 using @functions w/foreach

Hi there,

Is there a way to send a for each loop item to the functions validation? I have this so far:

Code:
 @if(IsPost){
        <h3>List of affected customers:</h3>
        foreach(var item in getList){
             @Functions.IsValidEmail(item.email) 
             @item.email    
        }
        }
It just false al the time so I know thats not right.

Thanks!

Laura
 
Old December 19th, 2013, 04:00 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Can you elaborate on what you're trying to accomplish?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 19th, 2013, 04:09 PM
Registered User
 
Join Date: Dec 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The application creates a list of emails in order to send an outage notification.

I am trying to allow the user to look at a list of emails before the email is sent to see if the emails are in the correct format so they can correct them in the database.

Code:
@{
     Layout = "~/_Layout.cshtml";

    var db = Database.Open("MySQLConnection");
    var csList = Request["affectedList"];
    var getList = db.Query("SELECT 'email1@gmail.com' as email union select 'email2@gmail.com' as email");
    
    var emailList = "SELECT email FROM dbo.vwOutagesEmail WHERE servicenumber IN ({0})";
        getList = db.QueryIn(emailList, csList);
}

<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
         <script>
            function goBack()
            {
            window.history.back()
                }
           </script>
        <title></title>
    </head>
    <body>
         @if(IsPost){
        <h3>List of affected customers:</h3>
        foreach(var item in getList){
             @Functions.IsValidEmail(email) 
             @item.email    
        }
        }

<button onclick="goBack()">Go Back</button>

 </body>
</html>
I'm using my emails to test for right now.

Thanks

Laura
 
Old December 19th, 2013, 04:23 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're validating email but shouldn't you be validating item.email? Also, you may want to wrap this in a if statement so only false addresses show up.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 19th, 2013, 04:24 PM
Registered User
 
Join Date: Dec 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

cool thanks! I will look up the if statement logic.

Thanks

Laura





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 4: ForEach Error b/c ENTBaseEOList does not contain GetEnumerator RWoodmansee BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 2 September 26th, 2012 11:46 AM
Chapter 4: Reusable Functions spasticjustice BOOK: Beginning ASP.NET Web Pages with WebMatrix 6 February 3rd, 2012 03:36 PM
Foreach in Chapter 6 sgtwwilson BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 2 January 22nd, 2010 08:57 PM
Functions, Chapter 3 Building a Method bodycode BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7 0 November 25th, 2009 06:23 PM
Chapter 2 functions mobyme BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 April 3rd, 2007 07:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.