Html.BeginForm () only with form id does not generate valid action url

I want to add formId to beginForm()

If I try to use Html.BeginForm(null, null, FormMethod.Post, new {@id="Id"})

then the generated html is <form action="/newquestion/payment/b9f88f80-f31f-4144-9066-55384c9f1cfc" ... >

I don't know how this URL is generated, so I tried,
Html.BeginForm(new {@id="Id"})
but then the action URL looks like this: <form action="/newquestion/payment/Id... >

In both cases, the action URL is not what it should be, and it does not fall into the controller post-action.

+4
source share
3 answers

When you try to generate a route, for example, using BeginForm, MVC will do everything possible to include in it what you might need.

domain.com/Home/Index/b9f88f80-f31f-4144-9066-55384c9f1cfc, , , .

controller / action / id
/Home      / Index  / b9f88f80-f31f-4144-9066-55384c9f1cfc

- (, ).

:

@using (Html.BeginForm(null, null, new { @id = string.Empty },
    FormMethod.Post, new { @id = "Id" }))
{

}

new { @id = string.Empty } - , .

+4

@id id.

 @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "MyForm1" }))    
    {
        <input id="submit" type="submit" value="Search" />
    }
+1

- System.Web.Mvc.Html( System.Web.Mvc.dll) : -

BeginForm ( HtmlHelper htmlHelper, string actionName,
controllerName, object routeValues, FormMethod, htmlAttributes)

: Html.BeginForm( string actionName, string controllerName, object routeValues, FormMethod, htmlAttributes)

, MVC 4

@using (Html.BeginForm(null, null, new { @id = string.Empty }, FormMethod.Post,
    new { @id = "trainingForm" }))
{
    <input id="TRAINER_LIST" name="TRAINER_LIST" type="hidden" value="">
    <input type="submit" value="Create" id="btnSubmit" />
}
0

All Articles