Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ViewBag in a using statement?

I am trying to use the ViewBag to display the action for a form in a partial page.

I have tried the following:

@using(Html.BeginForm(ViewBag.Action, "Person", FormMethod.Post)
@using(Html.BeginForm((ViewBag.Action), "Person", FormMethod.Post)
@using(Html.BeginForm(@(ViewBag.Action), "Person", FormMethod.Post)
@using(Html.BeginForm({ViewBag.Action}, "Person", FormMethod.Post)

But none of those work. What is the correct syntax?

like image 855
zgirod Avatar asked Dec 09 '25 01:12

zgirod


1 Answers

Try

@using(Html.BeginForm((string)ViewBag.Action, "Person", FormMethod.Post)
like image 90
marcind Avatar answered Dec 10 '25 19:12

marcind