How to update Methods to use HttpPost instead of HttpPost to resolve security concerns.

I have some methods in Controllers that I need to update to use the action verb [HttpPost] instead of [HttpGet].  When I do this, the code in the View no longer works.
Here is an example:

The Controller has the following method:

            public ActionResult MoveToReview(int id)
                  tbl_BOM bom = (from x in bomDB.tbl_BOM
                                       where x.ID == id
                                       select x).Single();

                  return RedirectToAction("Details", new { id = id });

The View uses this in a button:

<button class="btn btn-success col-xs-6 col-xs-offset-3" onclick="window.location = '@Url.Action("MoveToReview", "Report", new { id = })';">
                            Move To Review

If I update to use [HttpPost], I get an error.
Crystal RouseTask LeadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zephyr_hex (Megan)DeveloperCommented:
Your view will need to use a form set to POST with a submit button, or, your button needs to trigger an AJAX set to POST.

Right now, you have a button that makes an inline JS call to the MoveToReview view.

My recommendation would be to use a form with a hidden field for the id, change the button to type submit, and get rid of the inline JS.
zephyr_hex (Megan)DeveloperCommented:
So, something like this:

@using (@Html.BeginForm("MoveToReview", "MyController", FormMethod.Post))
     @Html.HiddenFor(m =>
     <button type="submit">Submit</button>


Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Crystal RouseTask LeadAuthor Commented:
Thank You!  I was able to get this to work by:

I added  [HttpPost] to the MoveToReview Method in my controller.

To my view I had to add:   master.Areas.MyAreaName.Models.TableName mytbl = new master.Areas.MyArea.Models.TableName();
Change my button to a FormPost as follows:

using (@Html.BeginForm("MoveToReview", "MyController", new { id = }, FormMethod.Post))
                             @Html.HiddenFor(x => mytbl.ID)
                            <button type="submit" class="btn btn-success col-xs-6 col-xs-offset-3">Move To Review</button>

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.