Reputation: 107
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
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
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
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
Reputation: 9881
Yes you can. In the action
property of the form in page.cshtml simply specify actionname:
<form action="actioname">
Upvotes: 1