代码之家  ›  专栏  ›  技术社区  ›  Andre Gallo

ASP。NET MVC:使用Edit操作时如何获取实际对象?

  •  1
  • Andre Gallo  · 技术社区  · 17 年前

    System.Web.Mvc.ViewPage<Foo>

    public ActionResult Edit(int id, FormCollection collection)
    

    public ActionResult Edit(int id, Foo myObject)
    

    编辑:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Edit(Foo myObject)
    {
    }
    

    我不知道,但效果很好。谢谢你的回答,这让我想到了这篇文章: http://www.haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx

    4 回复  |  直到 17 年前
        2
  •  0
  •   Community Mohan Dere    9 年前

        3
  •  0
  •   Davide Vosti    17 年前
        4
  •  0
  •   Adrian Grigore    17 年前

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Edit(int id, FormCollection collection)
    {
    
        LinqEntity entity = MyRepository.GetEntity(id);
        UpdateModel(entity);
    
        //validate and save your entity here
    
    }
    

    ScottGu's MVC Walkthrough