Let's take a look at the Action Method in the Controller in oxite.Code:
Namespace Oxite. controllers { Public class Areacontroller : Controller {[ Actionname ( "Find" ), Acceptverbs ( Httpverbs . Post)] Public Virtual Oxitemodellist < Area > Findquery (Areasearchcriteria Searchcriteria ){ Ilist < Area > Foundareas = areaservice. findareas (searchcriteria ); Oxitemodellist < Area > Model = New Oxitemodellist < Area > {List = foundareas}; model. addmodelitem (searchcriteria ); ReturnModel; }
Is there anything wrong with the above action method? How does the action method return a typeOxitemodellist<Area>? Isn't actionresult or void returned by the Controller's action method? Can the return value of action be of any type? I believe that when you see the action method code in the controller, you will also have such questions.
By default, the return value of action should be actionresult (recommended) or void. So why can we return a data set? You may thinkOxitemodellist<Area> Will it be inherited fromViewresultWhat about it? Sorry.Oxitemodellist<Area> Not inherited fromViewresult. When I was depressed, I suddenly sawContainerfactoryIactioninvoker is registered in IOC:
So I was very excited.OxitecontrolleractioninvokerLet's take a look at the details here:
Namespace Oxite. Infrastructure {Public class Oxitecontrolleractioninvoker : Controlleractioninvoker { Private readonly Ifilterregistry Filterregistry; Public Oxitecontrolleractioninvoker ( Ifilterregistry Filterregistry ){ This . Filterregistry = filterregistry ;} Protected override Actionresult Createactionresult
( Controllercontext Controllercontext, Actiondescriptor Actiondescriptor, Object Actionreturnvalue ){ If (Actionreturnvalue = Null ) {Controllercontext. Controller. viewdata. Model = New Oxitemodel {Container = New Notfoundpagecontainer ()}; Return new Notfoundresult ();} If ( Typeof ( Actionresult ). Isassignablefrom (actionreturnvalue. GetType ())) Return Actionreturnvalue As Actionresult ; Controllercontext. Controller. viewdata. Model = actionreturnvalue;Return newViewresult{Viewdata = controllercontext. Controller. viewdata, tempdata = controllercontext. Controller. tempdata }; }
OxitecontrolleractioninvokerThe inheritance relationships of are as follows::
Oxitecontrolleractioninvoker => Controlleractioninvoker-> iactioninvoker.
OxitecontrolleractioninvokerRewrittenControlleractioninvokerThe createactionresult method of. This method has a parameter named actionreturnvalue. From the parameter name, we can easily see the meaning of this parameter. Yes, she is the result returned by our action, from the code above, we can see that actionreturnvalue is assigned to viewdata. model, and then re-constructViewresult. I believe that after reading the above Code, you have suddenly become enlightened.
ThenOxitecontrollerfactoryPairControllerActioninvokerOxitecontrolleractioninvoker:
Namespace Oxite. Infrastructure {Public class Oxitecontrollerfactory : Defaultcontrollerfactory { Private readonly Iunitycontainer Container; Public Oxitecontrollerfactory ( Iunitycontainer Container ){ This . Container = container ;} Protected override Icontroller Getcontrollerinstance ( Type Controllertype ){Icontroller Icontroller = container. Resolve (controllertype) As Icontroller ; If ( Typeof ( Controller ). Isassignablefrom (controllertype )){ Controller Controller = icontroller As Controller ; If (Controller! = Null )Controller. actioninvoker = container. Resolve <Iactioninvoker> (); Return Icontroller ;} Return Icontroller ;}}}
Iactioninvoker has been registered previously:
Enjoy. By Q. Lee. Lulu