I have a weird case and I wanted your enlightenment. I have two controllers. One Person Controller for general Person use action methods and one Candidate Controller for more specific action methods related to Candidate. I use one partial view that is located under the Person folder in order to be used as generic in case I want to use it in the future for other types of Person. For the time being this partial view uses an Ajax.BeginForm targeting the Candidate Controller. The syntax I am using 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 of the fact that it targets an action in a different controller. Now for my form validation I had to put some more arguments to my Ajax.BeginForm. My new syntax is like that:
@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 way can't find the Action method. If I put my action inside the Person Controller it works correctly again. However I was wondering why is that case. I did some digging but I didn't manage to get an answer about that.
From firebug I see that the url the browser tries to post is for some reason
http://{ProjectName}/Person/SaveCandidateLanguage?Length=9
instead of
http://{ProjectName}/Candidate/SaveCandidateLanguage?Length=9
and naturally I get a 404 Not found response. I was also wondering what is the variable ?Length=9 that I see at the end of the url and where does it come from.
?length="9"
is because "Candidate" contains 9 characters andlength
is the only property ofstring
– Eniwetok