2014-03-14 30 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