2014-03-14 31 views
3

嘿,我Razor視圖傢伙,我有那將接受來自用戶的日期一個簡單的形式獲取日期值:如何從@using(Html.BeginForm(

@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(); 
    } 

所以我想知道我缺少什麼

回答

3

日期定義名稱像下面

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

這個名字應該與你的控制器動作的參數名稱相匹配。

如果是這樣,數值將被自動綁定。

+0

啊......非常感謝!將在幾分鐘內接受答案 – inside