开发者

MVC3 - RedirectToAction from Edit page back to Details page with parameter

开发者 https://www.devze.com 2023-04-03 23:49 出处:网络
I have a master detail scenario going from a list of categories to ingredients. In the Edit ActionResult I have:

I have a master detail scenario going from a list of categories to ingredients.

In the Edit ActionResult I have:

if (ModelState.IsValid){
    dc.Entry(mainingredient).State = EntityState.Modified;
    dc.SaveChanges();
    int ID = ??开发者_开发技巧???
    return RedirectToAction("Details", new { id = ID});
}
...

I am basically trying to go back to the page I came from. For example... from /Ingredient/Edit/2 back to Ingredient/Details/2

To make this question clearer: how do I pass an id from the edit get to edit httppost controller so that I can redirect the user back to the details page again passing the id after they make an update?


You could pass a url query string parameter to the Edit action when invoking it. This way you will be able to redirect to:

public ActionResult Edit(string returnUrl)
{
    ...
    return Redirect(url);
}

or if you already know the controller and action:

return RedirectToAction("Details", new { id = ID });

will be sufficient. The ID you want to redirect back could be passed as action argument.

0

精彩评论

暂无评论...
验证码 换一张
取 消