Get model from asp.net mvc action without using parameters
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:
[Http开发者_如何学JAVAPost]
public ActionResult SingleUser(Part part)
{
if(part == Part.General)
GeneralEditModel model = Model as GeneralEditModel;
else
ContactEditModel model = Model as ContactEditModel;
//....
}
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
精彩评论