5
I wonder if it’s possible to get the name of ActionResult
who called the View
.
I know that normally View
has the same name as ActionResult
, but in my case, I have a single view for two ActionResult
from within the View
I need to know which one ActionResult
will do the POST.
It would be something like:
@using (Html.BeginForm(ACTION_RESULT_QUE_CHAMOU_A_VIEW, "MeuController", FormMethod.Post, new { @class = "form-horizontal" }))
Updating
I was able to take Actionresult dynamically with:
ViewBag.ActionResult = ViewContext.RequestContext.RouteData.Values.Values.Where(w => w.Equals("Edit") || w.Equals("Create")).First().ToString();
I don’t know if it’s the best way, if it’s not please tell me.
Only now I had another problem. When I call my Beginform that way:
@using (Html.BeginForm(ViewBag.ActionResult, "MeuController", FormMethod.Post, new { @class = "form-horizontal" }))
I get the following error on the page:
Extension methods cannot be shipped dynamically. Consider converting dynamic arguments or calling the method extension without method syntax.
Someone knows how to fix this?
Gypsy, Thank you! That solves my last question. I marked @Harrypotter’s as an answer because his solves the whole problem.
– Renatto Machado