1

If so, how can I call it from my View?

The controller action that I have in mind is something like this:

public ActionResult UrunYonetimi<T>(int param = 0)
{
   // doing stuff
}

Can we have an action like this? If so, how can I specify that T from my e.g @Url.Action() call?

Halo
  • 1,524
  • 3
  • 24
  • 39
  • 3
    Is There a particular reason about it?. Could you explain why you want to do this? – Jorge Jul 09 '12 at 20:35
  • I have polymorphism regime going on in my models. I mean my models inherit from a base class, and I'd like to use the same action for different types, if possible. The controller action will use the base type – Halo Jul 09 '12 at 20:36
  • Base on your answer, why you just received the Parent class as a parameter in the Action? and then do the cast to the corresponding child – Jorge Jul 09 '12 at 20:39
  • I can do a conditional block, using `if(obj is something)` fashion, yes. But this way would look cooler I guess, for querying purposes. – Halo Jul 09 '12 at 20:41
  • Well I readlly don't know if it's possible, but let's wait if someone know's the answer – Jorge Jul 09 '12 at 20:55
  • Well I tried to call the action without much preparation, it gave me this error: **Cannot call action method 'System.Web.Mvc.ActionResult UrunYonetimi[T](Int32)' on controller 'Controllers.YoneticiController' because the action method is a generic method.** – Halo Jul 09 '12 at 20:58
  • take a look to this question http://stackoverflow.com/questions/6028744/generic-action-link-in-mvc-3-razor – Jorge Jul 09 '12 at 20:59

1 Answers1

0

I think I've come to an understanding for this issue:

I guess we need to declare our nice generic functions in the model rather than in the controller, and handle different types from there. We can and probably should have different actions and thus different URLs for every model type, but they will all call the same function from the model, only with different types.

Halo
  • 1,524
  • 3
  • 24
  • 39