asp.net mvc - How to get the Model from an ActionResult? -


i'm writing unit test , call action method this

var result = controller.action(123); 

result actionresult , need model somehow, knows how this?

in version of asp.net mvc there no action method on controller. however, if meant view method, here's how can unit test result contains correct model.

first of all, if return viewresult particular action, declare method returning viewresult instead of actionresult.

as example, consider index action

public viewresult index() {     return this.view(this.userviewmodelservice.getusers()); } 

you can model this

var result = sut.index().viewdata.model; 

if method signature's return type actionresult instead of viewresult, need cast viewresult first.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -