Ajax.BeginForm with 4 arguments not detecting an action method

I have a strange case, and I wanted your enlightenment. I have two controllers. One Person controller for common character usage methods and one candidate controller for more specific candidate actions. I use one partial view, which is located in the Person folder, to use it as a general one if I want to use it in the future for other Person types. So far, this partial view has been using Ajax.BeginForm aimed at the Candidate Controller. The syntax I use is

@using (Ajax.BeginForm("SaveCandidateLanguage", "Candidate",
    new AjaxOptions
    {
        HttpMethod = "Post",
        OnBegin = "onBeginFormValidation",
        OnSuccess = "onSaveCandidateLanguageSuccess"
    }))
{
    // form input elements
}

This type of Ajax.BeginForm works correctly, despite the fact that it targets actions in another controller. Now, to validate my form, I had to add a few more arguments to my Ajax.BeginForm. My new syntax is as follows:

@using (Ajax.BeginForm("SaveCandidateLanguage", "Candidate",
    new AjaxOptions
    {
        HttpMethod = "Post",
        OnBegin = "onBeginFormValidation",
        OnSuccess = "onSaveCandidateLanguageSuccess"
    },
    new
    {
        id = "addEditCandidateLanguageForm",
        novalidate = "novalidate"
    }))
{
   // form input elements
}

For some reason, this method cannot find the Action method. If I put my action in the Person Controller, it will work correctly again. However, I was wondering why this is so. I did digging, but I could not get an answer about this.

From firebug, I see that the URL that the browser is trying to publish is somehow

http: // {ProjectName} / Person / SaveCandidateLanguage? Length = 9

instead

HTTP: // {Project_name} / candidate / SaveCandidateLanguage Length = 9

, , 404 . , ? Length = 9, URL- .

+4
1

Ajax.BeginForm 11 . , :

Ajax.BeginForm(string actionName, string controllerName, AjaxOptions options)

, object routeValues:

Ajax.BeginForm(string actionName, object routeValues, AjaxOptions options, object htmlAttributes)

, , , :

Ajax.BeginForm(string actionName, string controllerName, object routeValues, AjaxOptions ajaxOptions, object htmlAttributes)

null, :

Ajax.BeginForm("SaveCandidateLanguage", "Candidate", null,
new AjaxOptions
{
    HttpMethod = "Post",
    OnBegin = "onBeginFormValidation",
    OnSuccess = "onSaveCandidateLanguageSuccess"
},
new
{
    id = "addEditCandidateLanguageForm",
    novalidate = "novalidate"
}))

?length="9" , "" 9 , -

+6

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


All Articles