4

私のかみそりビューには、ユーザーからの日付を受け入れる単純なフォームがあります。

@using (Html.BeginForm("CancelByDate", "ClassExample", FormMethod.Post, new { id = "dateForm" }))
   {
      <input id="dateInput" type="date" width="10" class="date" />
      <input type="submit" value="Continue" />
   }

CancelByDate アクションでこのデータを取得するにはどうすればよいですか?

私はいくつかの方法を試しました:

    public ActionResult CancelByDate(DateTime dateInput)  // <---- This value will be null
    {
        return View();  
    }

    public ActionResult CancelByDate(String dateInput)  // <---- This value will be null
    {
        return View();  
    }

    public ActionResult CancelByDate(object dateInput) // <---- This value will be some object, but there is no way to find out what is the underlying type even with GetType(); 
    {
        return View();
    }

だから私は何が欠けているのだろうか?

4

1 に答える 1

4

以下のように日付の名前を定義します

<input id="dateInput" type="date" width="10" class="date" name="dateInput"/>

この名前は、コントローラー アクションのパラメーター名と一致する必要があります。

その場合、値は自動的にバインドされます。

于 2014-03-14T05:49:02.023 に答える