Here is the scenario:
- A partial view is retrieved by some JavaScript (AJAX call to controller returning a partial view) and the HTML is added to the DOM
- The partial view contains a form rendered by
Ajax.BeginForm()
- When the form is submitted (submit button clicked), it posts twice
If I render the partial view with the original view with Html.Partial()
(instead of adding it using JavaScript) the form is only submitted once, as expected.
The script for adding the partial view looks like this:
$.ajax({
type: 'GET',
url: '/MyController/MyAction',
cache: false,
contentType: "application/html; charset=utf-8",
dataType: 'html',
success: function (result) {
$('#body').append(result);
}
});
Any ideas? :) Thanks!
Here is the scenario:
- A partial view is retrieved by some JavaScript (AJAX call to controller returning a partial view) and the HTML is added to the DOM
- The partial view contains a form rendered by
Ajax.BeginForm()
- When the form is submitted (submit button clicked), it posts twice
If I render the partial view with the original view with Html.Partial()
(instead of adding it using JavaScript) the form is only submitted once, as expected.
The script for adding the partial view looks like this:
$.ajax({
type: 'GET',
url: '/MyController/MyAction',
cache: false,
contentType: "application/html; charset=utf-8",
dataType: 'html',
success: function (result) {
$('#body').append(result);
}
});
Any ideas? :) Thanks!
Share Improve this question edited Apr 26, 2017 at 1:28 Ted Nyberg asked Oct 4, 2013 at 9:56 Ted NybergTed Nyberg 7,41110 gold badges44 silver badges82 bronze badges1 Answer
Reset to default 8I'm an idiot. My controller returned View instead of PartialView - so of course it contained all the JavaScript resources. In other words, problem was caused by double unobtrusive script links. :/