views:

58

answers:

1

I have a controller with the following actions:

public ActionResult Create()
{
    return View(new MyModel());
}

[HttpPost]
public ActionResult Create(MyModel model)
{
    //Update database
    ...
    //Pass the current model so we don't have to load it from the database
    return View("Details", model);
}

[HttpPost]
public ActionResult Details(MyModel model)
{
}

Both my create.aspx and Details.aspx page have a submit button. The submit on the create.aspx page will cause a record to be insert into the database, and then it goes to the details view. That part works fine, I can click the submit button, the record gets inserted and goes to the details view for that record. Now if I click submit in details view, the Create(MyModel model) still gets called. Shouldn't the Details(MyModel model) method get called?

In the method for the create post, I want to transfer to the details view and pass the current model, so that don't have to reload that data from the database.

+1  A: 

in your details view alter your Html.BeginForm to

<%= Html.BeginForm("Action","Contoller", new{}) %>

When you return "Details" view in Create action, Framework will not guess your intention. As a result it renders "Details" view but still thinks that it is a Create action and Html.BeginForm() helper method posts back to same action.

Alexander Taran
Ok, I got the Details(MyModel model) to be called but changing the BiginForm to <%= Html.BeginForm("Details","MyControler", Model) %> as you suggested. Works fantastic, thanks!
Jeremy