Link to home
Start Free TrialLog in
Avatar of Member_2_1242703
Member_2_1242703

asked on

Sending an input value from a view to a controller in MVC

I've got a textbox on a view

@Html.EditorFor(model => model.StartDate, new { htmlAttributes = new { @class = "form-control" } })

Open in new window


and I'm submitting data via my controller using

  public ActionResult Create([Bind(Include = "ID,StartDate,EndDate,Approval,Status,Type,Hours,Comments,FiscalYear,EMPLID,FiscalWeek,EarningsCode,ApprovalComments,ApprovedBy,ApprovedDate")] PTO_REQUEST pTO_REQUEST)
        {
            if (ModelState.IsValid)
            {
                pTO_REQUEST.Approval = false;
                pTO_REQUEST.Status = "Pending";
                pTO_REQUEST.FiscalYear = Fiscal.getFY(DateTime.Now);
                pTO_REQUEST.EMPLID = Helpers.User.GetEmployeeID();
                db.PTO_REQUEST.Add(pTO_REQUEST);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(pTO_REQUEST);
        }

Open in new window


I want to replace the DateTime.Now in

pTO_REQUEST.FiscalYear = Fiscal.getFY(DateTime.Now);

Open in new window


With the value of the aforementioned textbox above. How do I do that?
ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
P.S.  You likely should validate pTO_REQUEST.StartDate before you pass it to your getFY method.  You should make sure it's in the expected format and that it's a valid date, for example.
Avatar of Member_2_1242703
Member_2_1242703

ASKER

This CAN'T be this easy :-)
Thanks again, you rock!