从日期选择器和计算中发出填充标签

时间:2014-07-21 23:48:10

标签: javascript asp.net-mvc razor jquery-ui-datepicker

今天我一直在研究这个问题,我很难过。我正在尝试使用日期选择器选择日期并使用该日期,使用日期填充标签并从用户处获取输入以将日期添加到所选日期。日期选择器工作正常,但是我无法获得填充标签的日期,我不知道如何在该日期提前6天计算。添加日期的代码是直截了当的,我不知道如何获取日期并使其可计算。

这是我到目前为止所做的:

查看

    @{
    ViewBag.Title = "Index";
}

<link type="text/css" href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>

<form id="calendarForm" action="~/Views/Calendar/Calendar.cshtml" method="post">
    <h2>Calendar Application</h2>
    <p>This application will display a the specified number of days <br /> the user inputs on a calendar.</p>
    <br />
    <h2>Select A Date</h2>

    @model VanickCalendarApp.Models.Calendar

    <!-- Date picker visible -->
    <p>
        <input type="text" id="Date" />
    </p>

    <!-- Takes the date from the picker and calculates it new date on button click-->
    <script>

        $('button').click(function () {
            var datePickerSelected = $("#Date").datepicker("getDate");
            var endDate = new Date();
            var selDate = $('#Date').val();
            var DaysToBeAdded = addDaysEntered;
            endDate = (selDate + DaysToBeAdded);
        });

    </script>

    @using (Html.BeginForm("Calculate Days", "Calendar", FormMethod.Post))
    {
        <h2>Enter The Number Of Days To Display</h2>

        @Html.TextBoxFor(model => model.DaysToBeViewed)

        <label id="dateSelected">"Date"</label>
        <input type="button" value="Submit" onclick="daysAdded()" />
    }


        <!-- Create the date picker script -->
        <script>

        $(function () {
        $('#Date').datepicker();

    });

    </script>

    <!-- Creates an alert to test the values for debuging -->
     <script>
         document.getElementById('dateSelected').valueOf = dateSelected
         alert.valueOf("Date");

     </script>

</form>

控制器

using System.Web.Mvc;
using VanickCalendarApp.Models;


namespace VanickCalendarApp.Controllers
{
    public class CalendarController : Controller
    {

        public string CalculateDays(string Date)
        {
            var oneDAY = 1000 * 60 * 60 * 24;

             return Date;
        }
        //
        // GET: /Calendar/

        public ActionResult Calendar()
        {


            return View();
        }

        //
        // GET: /Calendar/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Calendar/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Calendar/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Calendar/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Calendar/Edit/5

        [HttpPost]

        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Calendar/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Calendar/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}

模型

using System;
using System.Web.Mvc;
using System.Data;
using System.Data.Entity;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

namespace VanickCalendarApp.Models
{
    public class Calendar
    {
        //[DataType(DataType.Date)]

        public string date { get; set; }
        public int DaysToBeViewed { get; set; }
        public DateTime newDate { get; set; }


    }
}

0 个答案:

没有答案