views:

57

answers:

1

Hi,

I have the following method in one of my Views,

public ActionResult EditRoute(int? id)
{
    // Do Work
    return View(new RoutingFormViewModel(obj1, obj2, obj3));
}

What I'd like to do is get the RoutingFormViewModel that is being passed to the view in my unit test, is this possible?

I've tried the following but don't seem to be getting anywhere:

ActionResult result = con.EditRoute(null);
ViewResult v = (ViewResult)result;

I'm basically looking how I can access the View's model from my test. Any help appreciated.

+3  A: 

Sure, just access the v.ViewData.Model property. Your Model will be there. But first check that your action worked as expected and the result is actually a ViewResult. I don't know if you have any other paths in the action code that could end in a different result.

Ariel Popovsky