代码之家  ›  专栏  ›  技术社区  ›  Alexander Prokofyev

POST-action方法的参数绑定

  •  0
  • Alexander Prokofyev  · 技术社区  · 15 年前

    获取删除 动作方法将DDW2File对象传递给视图。是否有可能以某种方式将此对象绑定回 DDW2文件 删除后 无效的 它的价值。

    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; }
    }
    

    谢谢

    1 回复  |  直到 15 年前
        1
  •  3
  •   Steve Willcock    15 年前

    假设您的参数名为ddw2file(根据您在其中的签名),则视图中表单中的类似内容应该可以工作。

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