Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using T4MVC, how to set the action attribute on an HTML form

I am taking my first teetering steps with submitting Html forms using jQuery. All works well, but would like to use the T4MVC to generate the action link.

This works with Html.BeginForm (and Ajax.BeginForm) because they take an ActionResult as the action generating param. Ie:

Is there a way to do:

<form method="POST" action="@MVC.???">

I suppose I could do:

@using (Html.BeginForm(MVC.MyArea.MyController.MyAction(),...,new {@id="myForm"}))
        {
            // Inputs
        }

But really wonder if T4MVC can handle this. Suspect not, but am new to it, so maybe am missing something?

(And yes, I know about Ajax.BeginForm, but am using the current project to learn more about MVC and jQuery).

like image 922
awrigley Avatar asked Jan 21 '23 10:01

awrigley


1 Answers

The following should work:

<form method="POST" action="@Url.Action(MVC.MyArea.MyController.MyAction())">

Or if you need to add extra route values:

<form method="POST" action="@Url.Action(MVC.MyArea.MyController.MyAction().AddRouteValues(new { @id = "myForm" }))">
like image 174
David Ebbo Avatar answered Feb 24 '23 12:02

David Ebbo