Below Ajax call is not invoking the Non controller method(Index) in .NET core 6.
$.ajax({
type: 'POST',
contentType: false,
processData: false,
url: form.action,
data: formData,
success: () => {
},
error: () => {
}});
Html :
<form method="POST" enctype="multipart/form-data">
@Html.AntiForgeryToken()
<div>
--------
----
--
</div>
<div class="btns">
<button class="fill reset-button" type="button">@Html.PropertyFor(model => model.ResetButtonText)</button>
<button class="fill send-button" type="button" this.disabled="true">@Html.PropertyFor(model => model.SendButtonText)</button>
</div>
<br />
<div class="se">
<div class="alert alert-info" style="display:none">Sending...</div>
<div class="alert alert-danger" style="display:none">There was an issue with the submitted data. Please correct any errors and resubmit.</div>
<div class="alert alert-success" style="display: none">Your message was sent successfully.</div>
</div>
</form>
Method :
[HttpPost]
[ValidateAntiForgeryToken]
public IViewComponentResult Index(Block currentContent, ViewModel viewModel)
{
//code
}
Hardcoded the url , still it is not invoking the Index method .
Ajax call should invoke Index method which is not part of Controllers folder.