Kobi Burnley
Kobi Burnley

Reputation: 107

Httppost different named view and action method

I have a view called "page.chtml" and I want to post from it to an action called "actionname"

[HttpPost]
public ActionResult actioname(...){...}

Is it possible?

Upvotes: 0

Views: 227

Answers (4)

Jeyhun Rahimov
Jeyhun Rahimov

Reputation: 3787

Yes You can use actioname in different controllers and post it:

in any view in any controller you can post:

@using (Html.BeginForm("actioname", "Controller", FormMethod.Post))
{

}

Upvotes: 0

Erik Noren
Erik Noren

Reputation: 4339

If you want to post a form to a different action name, you can use the HTML helper for that. In Razor syntax it looks like this:

@using (Html.BeginForm("actioname"))
{
  <!-- Form Fields -->
}

There are a few parameters you can use - the action is one, another is the controller in case you want to post to an ActionResult in a different controller than the one that handled the request for the page initially.

Upvotes: 0

Armen
Armen

Reputation: 1093

you can use Html helper for creating a form with your desire submit action

@using (Html.BeginForm("actionName", "ControllerName", FormMethod.Post, new { id = "FormId", name = "FormName" }))
{
   <div>//your page.cshtml inner html code goes here

}

Upvotes: 0

Andy T
Andy T

Reputation: 9881

Yes you can. In the action property of the form in page.cshtml simply specify actionname:

<form action="actioname">

Upvotes: 1

Related Questions