I am not sure if using session or tempdata is useful for this problem or even if it is i have no clue on how to do this. (Still getting the hang of MVC with asp.net).

Basically in my first view which is called the payment view, i have many fields which users fill in to donate to a specific charity. Now in order for this to be added to the database and complete the donation, I will create a confirmation page which will transfer all the data and display a non-editable text format on the confirmation page, giving all the the information the user has given in the fields i created. On the confirmation page i would like to a have a button called "Edit" which will allow the user to go back to the payment page where the data they inserted is still stored but is able to be modified by just simply clicking to the input fields. I think using session or tempdata is best for this but i am quite confused as if i do use this, when the user clicks donate on the final confirmation page, will the restart the site? Such as clear all the saved data. This is what i want. I want a method that allows the user to edit the current data stored by clicking on "Edit" on a different view and able to modify it on the payment view.

PAYMENT VIEW

    @model CharitySite.Models.Payment

@{
    ViewBag.Title = "Payment";
}






@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal centered">
        <h1>Syria</h1>
        <h4>DONATIONS</h4>

        <hr />
        <h2>PAYMENT</h2>
        <br />

        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            <h1>@ViewBag.Name</h1>
            <label> Full Name:</label>
            <input type="text" id="fullname" name="user_name" />
            <label> Amount:</label>
            <input type="text" id="ammount" name="user_ammount" />
            <label>Comment:</label>
            <input type="text" id="comment" name="user_comment" />
            <br /><br />
            @Html.LabelFor(model => model.CardName, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.CardName, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.CardName, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.CardNumber, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.CardNumber, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.CardNumber, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.ValidFrom, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.ValidFrom, new { htmlAttributes = new { @class = "form-control datepicker" } })
                @Html.ValidationMessageFor(model => model.ValidFrom, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Expires, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Expires, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Expires, "", new { @class = "text-danger" })

            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.CardSecurityCode, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.CardSecurityCode, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.CardSecurityCode, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.EmailAddress, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.EmailAddress, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.EmailAddress, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Address, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Address, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Address, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.City, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.City, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.City, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Country, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Country, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Country, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.PostCode, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.PostCode, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.PostCode, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}
<script type="text/javascript">


</script>

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

Payment Controller

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using CharitySite.Models;

namespace CharitySite.Controllers
{
    public class PaymentsController : Controller
    {
        private PaymentDBContext db = new PaymentDBContext();

        // GET: Payments
        public ActionResult Index()
        {
            return View(db.Payments.ToList());
        }

        // GET: Payments/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Payment payment = db.Payments.Find(id);
            if (payment == null)
            {
                return HttpNotFound();
            }
            return View(payment);
        }

        // GET: Payments/Create
        public ActionResult Payment()
        {
            var model = new Payment();
            model.ValidFrom = DateTime.Now;
            return View();
        }

        // POST: Payments/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Payment([Bind(Include = "ID,CardName,CardNumber,ValidFrom,Expires,CardSecurityCode,EmailAddress,Address,City,Country,PostCode")] Payment payment)
        {
            if (ModelState.IsValid)
            {
                db.Payments.Add(payment);
                db.SaveChanges();
                ViewBag.Name = TempData["Name"];
                ViewBag.Amount = TempData["Amount"];
                ViewBag.Comment = TempData["Comment"];
                return RedirectToAction("Index");
            }

            return View(payment);
        }


    }
}

Related posts

Recent Viewed