Using T4MVC how to set the action attribute in an HTML form

I take my first setup steps with submitting HTML forms using jQuery. Everything works well, but I would like to use T4MVC to create action links.

This works with Html.BeginForm (and Ajax.BeginForm) because they accept an ActionResult as a parameter for generating an action. I.e:

Is there any 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 wondering if the T4MVC can handle this. I suspect no, but I'm new to this, so maybe I missed something?

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

+4
source share
2 answers

The following should work:

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

Or, if you need to add additional route values:

 <form method="POST" action="@Url.Action(MVC.MyArea.MyController.MyAction().AddRouteValues(new { @id = "myForm" }))"> 
+9
source

I am using MVCFutures for this. Then you can do things like:

 @using (Html.BeginForm<ControllerController>(c => c.MyAction(null))) { // form } 

Forms will usually be submitted in c.Action (null), as these actions will often be associated with the model represented here by a null value.

Caution: MVC Futures BeginForm does not play well with MVCValidation (client side). If you use jquery client side validation you will have no problem.

0
source

Source: https://habr.com/ru/post/1340881/


All Articles