【问题标题】:Parameter binding of POST action methodPOST动作方法的参数绑定
【发布时间】:2009-04-22 11:07:52
【问题描述】:

您可以看到 GET Delete 操作方法将 DDW2File 对象传递给查看。是否有可能以某种方式将此对象绑定回 POST Delete 操作方法的 ddw2file 参数?现在我有 null 值了。

代码片段:

public class DDW2FileController : Controller
{
    ...

    public ActionResult Delete(string fileName)
    {
        return View(repository.GetFile(fileName));
    }

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Delete(DDW2File ddw2file)
    {
        repository.Delete(file);
        return RedirectToAction("Index");
    }
}

...

public class DDW2File
{
    public string Name { get; set; }
    public long Length { get; set; }
}

谢谢!

【问题讨论】:

    标签: asp.net-mvc controller


    【解决方案1】:

    假设您的参数名称是 ddw2file,根据您的签名,视图中的表单内的类似内容应该可以工作。

    <%=Html.TextBox("ddw2file.Name")%>
    <%=Html.TextBox("ddw2file.Length")%>
    

    【讨论】:

      猜你喜欢
      • 2018-10-12
      • 1970-01-01
      • 1970-01-01
      • 2011-04-20
      • 2018-12-21
      • 2021-09-05
      • 2020-01-06
      • 1970-01-01
      • 2012-11-22
      相关资源
      最近更新 更多