1

I'm sending 2 different models to the same action, for eg. I'm either sending the ContactEdit or GeneralEdit model to the same action. The action will need to determine which model is sent. Is there a way to do this? I have no problem passing a query param to tell which model was passed, but is there a way to do something like:

[HttpPost]
public ActionResult SingleUser(Part part)
{
    if(part == Part.General)
        GeneralEditModel model = Model as GeneralEditModel;
    else
        ContactEditModel model = Model as ContactEditModel;

    //....
}
1
  • 1
    Could you explain a little more why you are doing this? It seems to me it would be easier to have two separate actions. Commented Sep 17, 2011 at 5:59

1 Answer 1

2

You can name your elements and use a bind prefix. I believe if your method takes two parameters as two object types, the one will just be null if it's not found. See

MVC - Model binding with multiple entities on the same page

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.