tags:

views:

65

answers:

2

I have a controller that inherits from a base controller. Both have an edit (post) action which take two arguments:

On Base controller:

[HttpPost]
public virtual ActionResult Edit(IdType id, FormCollection form)

And in the derived controller:

[HttpPost]
public ActionResult Edit(int id, SomeViewModel viewModel)

If I leave it like this I get an exception because there is an ambiguous call. However, I can't use override on the derived action, because the method signatures don't exactly match. Is there anything I can do here?

+2  A: 

As addition to Developer Art's answer a workaround would be:

leave the base method as it is and in your derived class implement the base method and annotate it with [NoAction]

[NoAction]
public override ActionResult Edit(IdType id, FormCollection form)
{
   // do nothing or throw exception
}

[HttpPost]
public ActionResult Edit(int id, SomeViewModel viewModel)
{
   // your implementation
}
Fabiano
Ah, Ok. I'll give this a try...
UpTheCreek
Yep, that works. Seems a little hacky ;) so I leave the question open for a while in case there are other ideas - otherwise it'll do the job. Thanks.
UpTheCreek
+1  A: 

I'd chain it:

On Base controller:

[HttpPost]
public virtual ActionResult Edit(IdType id, FormCollection form)

And in the derived controller:

[HttpPost]
public virtual ActionResult Edit(IdType id, FormCollection form)
{
     var newId = //some enum? transform
     var boundModel = UpdateModel(new SomeViewModel(), form);

     return Edit( newId, boundModel );
}

[HttpPost]
public ActionResult Edit(int id, SomeViewModel viewModel)

I haven't tested this, passing a Post method to another Post should work. There could be security implications this way.

jfar
Thanks, I'll try this too.
UpTheCreek