是否可以在ActionLink中的View中引用ID /类?

问题描述

我尝试将View中“类”的值传递给控制器​​,并将其保存到数据库用户选择的日期存储在“ finalDate”类中(带有该日期字段和“保存”按钮的约100行):

查看:

<tr>
           <td>
                @Html.displayFor(modelItem => item.custName)
           </td>
           <td class="choice">
                <input class="finalDate" type="date">                
           </td>
           <td>
                @Html.ActionLink("Save","Update",new { cust = item.custName,manualDate = "{finalDate.value}" }) //can I pass class (or id) in that way?

           </td>
</tr>

控制器:

        public ActionResult Update(string cust,DateTime? manualDate)
        {

            _docs.UpdateData(cust,manualDate); //method UpdateData takes args and saves changes to db 

            return RedirectToAction("Index");
        }

问题是没有错误出现。无论如何,db都没有更改。所以我想知道是否:

  1. 我可以正确地将类值传递给ActionLink(这是可能的吗?)
  2. 我需要在<form action="@Url.Action("ActionName","Home"))" method="post">中包装View代码,才能将数据发送到服务器?
  3. 将[HttpPost]添加到ActionResult吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)