【问题标题】:how to get date value from the @using (Html.BeginForm(如何从 @using (Html.BeginForm(
【发布时间】:2014-03-14 05:47:13
【问题描述】:

在我的剃刀视图中,我有一个简单的表单,它将接受来自用户的日期:

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

所以我想知道我错过了什么?

【问题讨论】:

    标签: asp.net asp.net-mvc-4 razor actionresult html.beginform


    【解决方案1】:

    为日期定义一个名称,如下所示

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

    此名称应与控制器操作中的参数名称匹配。

    如果是这样,值将被自动绑定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-28
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 1970-01-01
      相关资源
      最近更新 更多