AustinT
AustinT

Reputation: 2026

Can POST and GET methods go to different views?

Would it be possible to have my POST method go to a different view to my GET method?

Example:

GET

    [HttpGet]
    public ActionResult Output()
    {
        var model = new VTOutputModel();
        return View(model);
    }

POST

    [HttpPost]
    public PartialViewResult OutputPartialView(VTOutputModel model)
    {
        return PartialView(model);
    }

Here I attempted to have the POST method pop up with a new webpage/view. Differing from the GET method. This doesn't work because it still expects a view called "Output"

Upvotes: 2

Views: 309

Answers (1)

Dan
Dan

Reputation: 5637

You can specify the name of the view you want to return by doing:

return View("OutputPost", model);

http://msdn.microsoft.com/en-us/library/dd460310(v=vs.98).aspx

As a full example:

[HttpGet]
public ActionResult Output()
{
    var model = new VTOutputModel();
    return View(model);
}

[HttpPost]
public ActionResult Output(VTOutputModel model)
{
    return PartialView("OutputPost", model);
}

Upvotes: 4

Related Questions