1

私はASP.Net MVC4を使用しています.Jquery UIの日付ピッカーを使用して日付フィールドを処理しています.コードで変数を使用する方法を知りたいです.

@Html.ActionLink("新規作成", "作成")

<script>
    $(function () {
        $("#from").datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 3,
            onSelect: function (selectedDate) {
                $("#to").datepicker("option", "minDate", selectedDate);
            }
        });

        $("#to").datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 3,
            onSelect: function (selectedDate) {
                $("#from").datepicker("option", "maxDate", selectedDate);
            }
        });
    });
</script>


<p>
<label for="from">From</label>
<input type="date" id="from" name="from" value='<%=from%>'/>
<label for="to">to</label>
<input type="date" id="to" name="to" value='<%=to%>'/>
</p>

「from」/「to」フィールドから取得した値を使用して、 Controller でそれらを操作したいと思います。

  public ActionResult index( )
        {
            DateTime first = 

            return View();
        }
4

2 に答える 2

0

から:

<label for="from">From</label>
<input type="date" id="from" name="from" value='<%=from%>'/>
<label for="to">to</label>
<input type="date" id="to" name="to" value='<%=to%>'/>

に:

@using(Html.BeginForm("ActionName", "ControllerName", FormMethod.Post)){
    <label for="from">From</label>
    <input type="date" id="from" name="from" value='<%=from%>'/>
    <label for="to">to</label>
    <input type="date" id="to" name="to" value='<%=to%>'/>
    <input type="submit" value="Submit Form" />
}
于 2013-04-06T16:12:03.007 に答える
0

HTML フォームを使用できます。

@using (Html.BeginForm())
{
    <p>
        <label for="from">From</label>
        <input type="date" id="from" name="from" value='<%=from%>'/>
        <label for="to">to</label>
        <input type="date" id="to" name="to" value='<%=to%>'/>
    </p>    
    <button type="submit">OK</button>
}

そして、呼び出されてフィールドのパラメーターとして渡されるコントローラー アクション:

[HttpPost]
public ActionResult Index(DateTime from, DateTime to)
{
    // when the form is submitted this action will be invoked and passed the 
    // selected values
    ...
}
于 2013-04-06T16:12:57.180 に答える