How to access RedirectToAction() function in Models classes in asp.net mvc2
How to access RedirectToAction() function in Models classes in asp.net mvc2. When i try to write it in one of my models classes it says 'The name RedirectToAction does not exists in t开发者_如何学Gohe current context'
Technically you can't call it because it is a method on the Controller class. It returns a RedirectToRouteResult object, which you could create if you wanted in your model, but you shouldn't. The model is the wrong place to be choosing what type of result to return, this should be a function of the controller.
The reason that you won't want your model to create an ActionResult is that it should be unaware of what type of I/O and display system you are using. Your model should be independent enough that you could use it with a web app, a command-line program, or a desktop app without change. By introducing controller- (or view-)related code into your model you are increasing its coupling and complexity unnecessarily and decreasing your ability to reuse it in another context.
精彩评论