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
Solved

error when updating forms with 'mvc'

Posted on 2014-09-10
5
193 Views
Last Modified: 2014-09-17
I have forms on a /check/confirm.cshtml page with two buttons, 'Update' & 'Confirm'
When I click on the Update button, it does not update the form, but is transferred to page
/checkout/completed.cshtml
For clarity the complete code is below:
Thanks in advance for any help given.
@model CheckoutConfirmModel
@using Nop.Core.Domain.Orders;
@using Nop.Web.Models.Checkout;
@using Nop.Web.Models.Common;
@using Nop.Web.Models.ShoppingCart;
@{
    Layout = "~/Views/Shared/_ColumnsThree.cshtml";
    ViewBag.Title = "Create";
    Int32 nCount = Convert.ToInt32(Session["nCount"]);
    var result = "";
    if (IsPost)
    {
        var firstName = Request["FirstName"];
        var lastName = Request["LastName"];
        var email = Request["Email"];
        var userData = firstName + "," + lastName +
            "," + email + Environment.NewLine;
        var dataFile = Server.MapPath("~/App_Data/data" + @Session["CustId"] + ".txt");
        File.AppendAllText(@dataFile, userData);
        result = "Information saved.";
    }
}
<div id="page shopping-cart-page" style="border:0px solid red; width:680px; height:130px; background-color: white; margin-left:15px;">
    @Html.Action("CheckoutProgress", "Checkout", new { step = CheckoutProgressStep.Cart })
    <div class="page-title"><br />
        <h2>Your&nbsp;@T("ShoppingCart")</h2>
        <span id="spanEnquiry" style="position:absolute;top:265px;left:550px;color:Black;" >
        <b>Thank you for enquiring about this product.</b></span>
        </div>
</div>
<h2>&nbsp;&nbsp;&nbsp;&nbsp;Order</h2>
@using (Html.BeginRouteForm("CheckoutConfirm", "Confirm", FormMethod.Post, new { id = "confirm-order-form" }))
{
    @*Based on your object to change the Id to the Corresponding property name*@
    @Html.HiddenFor(Model => Model.id)
    <div id="fldset" style=" position:relative; background-color:White; left:15px; width:680px;">
    <br />
    <fieldset>
        <legend>Information</legend>
                <p>Please give us a little more information about your printing / embroidery requirements<br />               
                Any additional information on the garments you want us to have?<br />
                Only complete the following information once you have finished adding products<br /> 
                to your enquiry and are ready to submit<br />
                </p>
                <p>
                Please give us a little more information about your printing / embroidery requirements<br />
                (e.g. position of the logo, sizing, number of colours, if plain text is required...): *
                </p>  
        <input type="submit" name="nextstep" value="@T("Checkout.ConfirmButton")" class="Button3" /><br />    
    </fieldset>
    </div>
}
            <div class="editor-field" style=" position:relative; background-color:White; left:15px; width:680px;">
            <fieldset>
            <legend>Information</legend>     
           <form id="form1" method="post" action="Confirm" >
           @*Based on your object to change the Id to the Corresponding property name*@
           @Html.HiddenFor(Model => Model.id)
           <table>
            <tr>
                <td>First Name:</td>
                <td><input id="FirstName" name="FirstName" type="text" /></td>
            </tr>
            <tr>
                <td>Last Name:</td>
                <td><input id="LastName" name="LastName" type="text" /></td>
            </tr>
            <tr>
                <td>Email:</td>
                <td><input id="Email" name="Email" type="text" /></td>
            </tr>
            <tr>
                <td>@Html.ActionLink("Go to Display", "", "Checkout/Completed")</td>
                <td><input type="submit"  value="Update" class="Button3"/></td>
            </tr>
        </table>
        </form>
        </fieldset>
        </div>
        <div style=" position: relative; top:0px; left:15px; width:705px;width:680px; background-color:White; color:Maroon; font-size:small;">
        <fieldset>
        <legend>Information</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.OrderEnquiry)
        </div>
        <div class = "order-enquiry">
            AddInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:@Session["AdditionalInformation"]#<br />
            CustomeId&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:@Session["CustId"]#<br />
         </div>
            
            @if (result != "")
            {
            <p>Result: @result</p>
            }
        </fieldset>
        </div>

Open in new window

0
Comment
Question by:homeshopper
  • 4
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40316049
What do you mean by "update the form?" What is it updating? As you've written it, the update button is a submit-type <input>, so it will post the form when you click it.
0
 

Author Comment

by:homeshopper
ID: 40316357
Hi Kaufmed,
Just to clarify the confusion, there are two code blocks below.
The first code block is the confirm page as it was originally.
It has a confirm button that transfers the page to the completed page.
The second code block is what I called an update page.
It has a button that should update or append the content of the textboxes
to a text file named as the customerId and stay on the same page,
but it does not, it just transfers the confirm page to the completed page
and the text file is not updated. I also wanted to conbine it all as one page.
Thanks in adavnce for any help given.
Best Regards, Ian.
@model CheckoutConfirmModel
@using Nop.Core.Domain.Orders;
@using Nop.Web.Models.Checkout;
@using Nop.Web.Models.Common;
@using Nop.Web.Models.ShoppingCart;
@{
    Layout = "~/Views/Shared/_ColumnsThree.cshtml";
    ViewBag.Title = "Create";
    Int32 nCount = Convert.ToInt32(Session["nCount"]);
}
<div id="page shopping-cart-page" style="border:0px solid red; width:680px; height:130px; background-color: white; margin-left:15px;">
    @Html.Action("CheckoutProgress", "Checkout", new { step = CheckoutProgressStep.Cart })
    <div class="page-title"><br />
        <h2>Your&nbsp;@T("ShoppingCart")</h2>
        <span id="spanEnquiry" style="position:absolute;top:265px;left:550px;color:Black;" >
        <b>Thank you for enquiring about this product.</b></span>
        </div>
</div>
<h2>&nbsp;&nbsp;&nbsp;&nbsp;Order</h2>
@using (Html.BeginRouteForm("CheckoutConfirm", "Confirm", FormMethod.Post, new { id = "confirm-order-form" }))
{
    @*Based on your object to change the Id to the Corresponding property name*@
    @Html.HiddenFor(Model => Model.id)
    <div id="fldset" style=" position:relative; background-color:White; left:15px; width:680px;">
    <br />
    <fieldset>
        <legend>Information</legend>
                <p>Please give us a little more information about your printing / embroidery requirements<br />               
                Any additional information on the garments you want us to have?<br />
                Only complete the following information once you have finished adding products<br /> 
                to your enquiry and are ready to submit<br />
                </p>
                <p>
                Please give us a little more information about your printing / embroidery requirements<br />
                (e.g. position of the logo, sizing, number of colours, if plain text is required...): *
                </p>  
        <input type="submit" name="nextstep" value="@T("Checkout.ConfirmButton")" class="Button3" /><br />    
    </fieldset>
    </div>
}

Open in new window

@model CheckoutConfirmModel
@using Nop.Core.Domain.Orders;
@using Nop.Web.Models.Checkout;
@using Nop.Web.Models.Common;
@using Nop.Web.Models.ShoppingCart;
@{
    var result = "";
    if (IsPost)
    {
        var firstName = Request["FirstName"];
        var lastName = Request["LastName"];
        var email = Request["Email"];
        var userData = firstName + "," + lastName +
            "," + email + Environment.NewLine;
        var dataFile = Server.MapPath("~/App_Data/data" + @Session["CustId"] + ".txt");
        File.AppendAllText(@dataFile, userData);
        result = "Information saved.";
    }
}
<div class="editor-field" style=" position:relative; background-color:White; left:15px; width:680px;">
            <fieldset>
            <legend>Information</legend>     
           <form id="form1" method="post" action="Confirm" >
           @*Based on your object to change the Id to the Corresponding property name*@                  
           @Html.HiddenFor(Model => Model.id)                   
           <table>
            <tr>
                <td>First Name:</td>
                <td><input id="FirstName" name="FirstName" type="text" /></td>
            </tr>
            <tr>
                <td>Last Name:</td>
                <td><input id="LastName" name="LastName" type="text" /></td>
            </tr>
            <tr>
                <td>Email:</td>
                <td><input id="Email" name="Email" type="text" /></td>
            </tr>
            <tr>
                <td>@Html.ActionLink("Go to Display", "", "Checkout/Completed")</td>
                <td><input type="submit"  value="Update" class="Button3"/></td>
            </tr>
        </table>
        </form>
        </fieldset>
        </div>
        <div style=" position: relative; top:0px; left:15px; width:705px;width:680px; background-color:White; color:Maroon; font-size:small;">
        <fieldset>
        <legend>Information</legend>
        <div class="editor-label">  
        @Html.LabelFor(model => model.OrderEnquiry)     
        </div>
        <div class = "order-enquiry">
            AddInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:@Session["AdditionalInformation"]#<br />
            CustomeId&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:@Session["CustId"]#<br />
         </div>
            
            @if (result != "")
            {
            <p>Result: @result</p>
            }
        </fieldset>
        </div>

Open in new window

0
 

Author Comment

by:homeshopper
ID: 40320623
I have found a solution myself as follows.
Changed <form id="form1" method="post" action="Confirm" >
to            <form id="form1" method="post" action="Confirm" >
Then in the CheckoutController.cs new routine as follows based on the Confirm routine,
but without redirect code etc.
[HttpPost, ActionName("txtConfirm")]
        [ValidateInput(false)]
        public ActionResult ConfirmOrder2()
        {
            //validation
            //
            //return RedirectToRoute("CheckoutCompleted");
              return View(model);
        }

Open in new window

0
 

Accepted Solution

by:
homeshopper earned 0 total points
ID: 40320624
Typo in post above, should be <form id="form1" method="post" action="txtConfirm" >
[HttpPost, ActionName("txtConfirm")]
        [ValidateInput(false)]
        public ActionResult ConfirmOrder2()
        {
            //validation
            //
            //return RedirectToRoute("CheckoutCompleted");
              return View(model);
        }

Open in new window

0
 

Author Closing Comment

by:homeshopper
ID: 40327521
I found the solution myself
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often people are aiming at development of perfect Magento websites. Though, it is easier said than done. You know what’s much easier? To ruin everything. It can be done in seconds. Many of us experimented with design, tried to change some values dir…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

828 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