Samantha J T Star
Samantha J T Star

Reputation: 32808

How can I check the HTTP response from inside a MVC controller?

I have:

    [HttpPost]
    public ActionResult Create(EditViewModel viewModel)
    {
        ...
    }

I know I can check the viewModel object when debugging but how can I get the actual HTTP response from within the controller at the "..." point?

Also how can I see the data that gets bound to the viewModel (without looking at the viewModel). Where's that data stored in the Response object?

Upvotes: 0

Views: 442

Answers (1)

Eranga
Eranga

Reputation: 32437

If you add FormCollection as a parameter to your POST action method, MVC will populate it with the posted form data. Or through the Form property of the Request

[HttpPost]
public ActionResult Create(EditViewModel viewModel, FormCollection formCollection)
{
    var name = formCollection["name"];

    var email = Request.Form["email"];
}

But modifying it inside the controller violates the whole "MVC" pattern.

Upvotes: 1

Related Questions