I wonder if it's possible to get the name of ActionResult
that called View
.
I know that View
normally has the same name as ActionResult
, but in my case, I have a single view for two ActionResult
different, hence within View
I need to know which of the ActionResult
will do POST .
It would be something like:
@using (Html.BeginForm(ACTION_RESULT_QUE_CHAMOU_A_VIEW, "MeuController", FormMethod.Post, new { @class = "form-horizontal" }))
Update
I was able to get ActionResult dynamically with:
ViewBag.ActionResult = ViewContext.RequestContext.RouteData.Values.Values.Where(w => w.Equals("Edit") || w.Equals("Create")).First().ToString();
I do not know if it's the best way, if not please, tell me.
But now I have another problem. When I call my BeginForm this way:
@using (Html.BeginForm(ViewBag.ActionResult, "MeuController", FormMethod.Post, new { @class = "form-horizontal" }))
I get the following error on the page:
Extension methods can not be dispatched dynamically. Consider converting the dynamic arguments or invoking the extension without the method syntax.
Does anyone know how to solve this?