ich viele ähnliche Ansichtsmodell haben:asp.net Mvc füllen Ansichtsmodell von Formcollection
public class RequestForSalaryVM : StatementViewModel
{
// RequestForSalaryVM properties
}
public class ReliefVM : StatementViewModel
{
// ReliefVM properties
}
und viele ähnliche Methoden:
[HttpPost]
public ActionResult SaveRelief(User currentUser, ReliefVM statement)
{
ReliefVM model = (ReliefVM)SaveModel(currentUser, statement);
if (model == null)
return RedirectToAction("List");
return View("Relief", model);
}
[HttpPost]
public ActionResult SaveRequestForSalary(User currentUser, RequestForSalaryVM statement)
{
RequestForSalaryVM model = (RequestForSalaryVM)SaveModel(currentUser, statement);
if (model == null)
return RedirectToAction("List");
return View("RequestForSalary", model);
}
Ich möchte so etwas bekommen:
[HttpPost]
public ActionResult SaveStatement(User currentUser, FormCollection statement, string ViewModelName)
{
Assembly assembly = typeof(SomeKnownType).Assembly;
Type type = assembly.GetType(ViewModelName);
object ViewModel = Activator.CreateInstance(type);
//Fill ViewModel from FormCollection <= how can I use asp.net mvc binding for this?
//I do not want to create their own implementation of asp.net mvc binding
return View(ViewModelName, ViewModel);
}