c# - How do I declare an MVC 5 action like in Web API 2? -
in web api declare actions this:
[responsetype(typeof(mymodel))] public async task<ihttpactionresult> get(httprequestmessage request, int accountid) { //get mymodel return ok(mymodel); } i request being passed in rather obtaining controller. mvc that? have been searching cant find examples or references ability.
edit: also, return interface. looking in mvc:
[responsetype(typeof(mymodel))] public async task<iactionresult> get(httprequestmessage request, int accountid) { //get mymodel return view(mymodel); }
its bit different mvc, actions map user interactions, not directly httprequest such. designed pass in model , respond view(). typically dont need check things headers , method type because need part of method parameters. if need view specific method type, can decorate [httppost] or [httpget] etc.
you can current httpcontext via static property httpcontext.current.httprequest directly controller action enough
Comments
Post a Comment