Hi, I have two strongly typed partial views of 2 Models for Create. both the forms are caling the same action. hence, i want the parameter to be dynamic so that i can cast it based on the type i am passing.
[HttpPost]
public ActionResult RegisterChannelPartner(dynamic channelPartner, string type)
{
try
{
channelPartner; // i would like to cast this dynamic object to a Model type before saving to database.
string encodedPassword = Utilities.EncodePassword(channelPartner.Password);
channelPartner.Password = encodedPassword;
var stakeHolder = new Stakeholder();
stakeHolder.FirstName = channelPartner.FirstName;
stakeHolder.LastName = channelPartner.LastName;
}
}
shivdilse
Member
8 Points
46 Posts
How to pass dynamic Model as a parameter to Controller action
Jan 22, 2013 02:06 PM|LINK
Hi, I have two strongly typed partial views of 2 Models for Create. both the forms are caling the same action. hence, i want the parameter to be dynamic so that i can cast it based on the type i am passing.
[HttpPost] public ActionResult RegisterChannelPartner(dynamic channelPartner, string type) { try { channelPartner; // i would like to cast this dynamic object to a Model type before saving to database. string encodedPassword = Utilities.EncodePassword(channelPartner.Password); channelPartner.Password = encodedPassword; var stakeHolder = new Stakeholder(); stakeHolder.FirstName = channelPartner.FirstName; stakeHolder.LastName = channelPartner.LastName; } }pls help
ignatandrei
All-Star
134903 Points
21619 Posts
Moderator
MVP
Re: How to pass dynamic Model as a parameter to Controller action
Jan 22, 2013 02:23 PM|LINK
It is not a reason. Make 2 separate actions.
However, if you want this, you can put channelPartner as object and make a custom ModelBinder
read http://odetocode.com/blogs/scott/archive/2009/04/27/6-tips-for-asp-net-mvc-model-binding.aspx
shivdilse
Member
8 Points
46 Posts
Re: How to pass dynamic Model as a parameter to Controller action
Jan 23, 2013 11:30 AM|LINK
Thank you , It was very helpful :)