kevin.upshaw Posted May 3, 2012 Share Posted May 3, 2012 Hi. Quite new to ASP.NET, doing a web design course. I have built a website, and am just building the order part - this is for an assignment. This is the code I have so far: @{ Layout="~/Shared/accountArea.cshtml"; Page.Title="New Order | Sarnies For All"; if (!WebSecurity.IsAuthenticated) { Response.Redirect("~/"); } var db = Database.Open("sarniesForAllCurrent");} <h1>New Order</h1> <p>Here you can create your own sandwich. First of all select your desired bread type from the drop down box below. Then move on to select the filling which you would like in your sandwich/wrap/baguette.</p> <p>All the products shown on this page are in stock, there will be no ringing you informing you that we can't make your order! If you have any issues with this, or have a special request don't hesitate to give us a call or use the Contact Us page.</p> <form id="newOrder" method="post" action="mailto:kevin.upshaw@live.co.uk"> <h2>Choose Bread Type</h2> <fieldset class="newOrder"> <div class="panel"> @{ var extractAvailableBread = "SELECT breadId, breadDescription, price, imgReference FROM [bread] WHERE UPPER(available) = 'YES' ORDER BY breadId "; } @foreach (var row in db.Query(extractAvailableBread)) { <div class="productArea"> <div class="productTitleArea"> <p class="productTitle">@row.breadDescription</p> </div> <div class="productImageArea"> <img class="productImage" src="@row.imgReference" alt="| Sarnies For All" /> </div> <div class="productPriceArea"> <p class="productPrice">£@row.price</p> </div> <div class="productSelectionArea"> <p class="productSelection"><input type="radio" name="breadSelection" value="@row.breadDescription" /></p> </div> </div> } </div> <p class="flip">Open/Close Available Bread Selection</p> </fieldset> <h2 class="clearBreak">Choose Your Filling</h2> <fieldset class="newOrder"> <div class="panel1"> @{ var extractAvailableFilling = "SELECT fillingDescription, price, imgReference FROM [filling] WHERE UPPER(available) = 'YES' ORDER BY filling "; } @foreach (var row in db.Query(extractAvailableFilling)) { <div class="productArea"> <div class="productTitleArea"> <p class="productTitle">@row.fillingDescription</p> </div> <div class="productImageArea"> <img class="productImage" src="@row.imgReference" alt="| Sarnies For All" /> </div> <div class="productPriceArea"> <p class="productPrice">£@row.price</p> </div> <div class="productSelectionArea"> <p class="productSelection"><input type="radio" name="fillingDescription" value="@row.fillingDescription" /></p> </div> </div> } </div> <p class="flip1">Open/Close Available Fillings Selection</p> </fieldset> <h2>Choose Salad Type</h2> <fieldset class="newOrder"> <div class="panel2"> @{ var extractAvailableSalad = "SELECT saladDescription, price, imgReference FROM [salad] WHERE UPPER(available) = 'YES' ORDER BY saladId "; } @foreach (var row in db.Query(extractAvailableSalad)) { <div class="productArea"> <div class="productTitleArea"> <p class="productTitle">@row.saladDescription</p> </div> <div class="productImageArea"> <img class="productImage" src="@row.imgReference" alt="| Sarnies For All" /> </div> <div class="productPriceArea"> <p class="productPrice">£@row.price</p> </div> <div class="productSelectionArea"> <p class="productSelection"><input type="radio" name="saladDescription" value="@row.saladDescription" /></p> </div> </div> } </div> <p class="flip2">Open/Close Available Salad Selection</p> </fieldset> <h2 class="clearBreak">Confirmation</h2> <p>Please confirm your selections and then hit the "Create" order button below. Your order will then be submitted and you will be redirected to your account.</p> <input type="submit" id="submit" name="submit" value="Create Order" /> <input type="reset" id="resetOrderForm" name="resetOrderForm" value="Reset Order Form" /> </form> All the code I have works absolutely fine so far. It queries the "bread" table in the database for "available" bread. The idea I had now is that for each section the user would select one option (hence the use of radio buttons) and when the user selects the option in each section the "*Id" for the option selected is stored in a variable - in which I can then do a SQL INSERT INTO - into the order database. However everything I try code wise has failed on me and wondering if anyone has any suggestions/advice? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 3, 2012 Share Posted May 3, 2012 Where are you stuck, are you able to get the radio button values from the form? Link to comment Share on other sites More sharing options...
kevin.upshaw Posted May 3, 2012 Author Share Posted May 3, 2012 I'm not really sure where to start. On my "New Order" page I have the following code: <form id="newOrder" method="post" action="processOrder.cshtml"> Then on the "processOrder.cshtml" page I tried the following: @{ Layout="~/Shared/accountArea.cshtml"; Page.Title="Process Order | Sarnies For All"; if (WebSecurity.IsAuthenticated == false) { Response.Redirect("~/"); } if (IsPost) { var breadSelection = breadSelection.Value; } } <h1>Order Status</h1><p>@breadSelection</p> I tried the above just to see if it would pull the selected value of data through to the process order page - and then tried to print it on the page. I however get the following error: Compilation ErrorDescription: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0841: Cannot use local variable 'breadSelection' before it is declaredSource Error: Line 10: if (IsPost) Line 11: {Line 12: var breadSelection = breadSelection.Value;Line 13: }Line 14: Source File: c:\sarniesForAllCurrent\processOrder.cshtml Line: 12 Managed to get this far, not quite sure how to get this to work though. Kev Link to comment Share on other sites More sharing options...
justsomeguy Posted May 3, 2012 Share Posted May 3, 2012 You need to use the Request.Form array to get data from a form using the post method. http://blog.scnetstudio.com/post/2011/06/12/Passing-value-within-2-page-using-Razor-syntax.aspx Link to comment Share on other sites More sharing options...
kevin.upshaw Posted May 5, 2012 Author Share Posted May 5, 2012 Again, that worked a treat, thanks for your help. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now