myahyagunes
7/6/2018 - 8:28 PM

Begin Form Dynamic Method Name

BeginForm'da method ismini dinamik olarak değiştirir.

@using(Html.BeginForm(Model.Action,"Controller"))

public string Action{
  
  get{
    Expression<Func<Controller,ActionResult>> update = (c=>c.Update(this));
    Expression<Func<Controller,ActionResult>> create = (c=>c.Create(this));
    
    var action = (Id != 0) ? update : create;
    return (action.Body as MethodCallExpression).Method.Name;
  }
  
}