Sunday, May 1, 2011

Parameter binding of POST action method

You can see what GET Delete action method passes DDW2File object to view. Is it possible somehow to bind this object back to ddw2file parameter of POST Delete action method? Now I have null value in it.

Code fragment:

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

Thanks!

From stackoverflow
  • Something like this inside a form in the view should work assuming your parameter name is ddw2file as per your signature there.

    <%=Html.TextBox("ddw2file.Name")%>
    <%=Html.TextBox("ddw2file.Length")%>
    
    Alexander Prokofyev : Thanks. Now also reading about ModelBinders...

0 comments:

Post a Comment