Post from external site to MVC controller that has typed parameters
I'm new to MVC so I was struggling with the title of the question -- not sure if there's anything already covering what I want to do.
Suppose I have a controller: FooController. It handles a set of views, all of which do the same basic thing, but use different models for various reasons. So I create an action for each model, and this works well:
[HttpPost]
public ActionResult Bar(Type1 t);
[HttpPost]
public ActionResult Bar(Type2 t);
etc...
What I want to accomplish (if possible) is to create an action that can accept a POST from a 3rd party website (in addition to the typed-views locally) and I can't seem to开发者_开发问答 figure out how to accept the data without MVC throwing an exception:
The current request for action 'Bar' on controller type 'FooController' is ambiguous between the following action methods:
And it lists the above actions.
I've tried a couple things:
- Created a method Bar(ExternalSiteType t) - Exception
- Created a method Bar(ExternalSiteParam1 p, ExternalSiteParam2 p2) - Exception
- Commented out the other actions - Success for both methods above
Any ideas how to get this to work?
EDIT: Route examples
/Foo/Bar/Type1
/Foo/Bar/Type2
/Foo/Bar/ExternalSite
I don't think
[HttpPost]
public ActionResult Bar(Type1 t);
[HttpPost]
public ActionResult Bar(Type2 t);
could work at all, even if it was from the same site. You can't have two actions with the same name unless they use different Http verbs ([HttpGet],[HttpPost]
etc).
Your best best would be to create an action with a different name for the external site, convert the passed in information to Type1
and then Redirect to Bar(Type1 t)
. See ASP.NET MVC Redirect with model for different ways you could Redirect and preserve your complex object.
精彩评论