0

I am working on an Asp.Net MVC core web application, and i have added the following form inside my razor view, to build an Ajax form:-

<form method="get" data-ajax="true" data-ajax-url="/Submission/Create" data-ajax-method="get" data-ajax-update="#panel" data-ajax-failure="failed">
                    <div class="form-group">
                        <input type="submit" value="Submit" class="btn btn-primary" />
                    </div>

</form>

and i added the following inside the script:-

@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");
     <script src="~/js/jquery.unobtrusive-ajax.js"></script>

    }
}

but when i click on the submit button i got this error on the browser console:-

HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
(XHR)GET - https://localhost:44363/Submission/Create?X-Requested-With=XMLHttpRequest&_=1590002030070

any advice?

John John
  • 1
  • 72
  • 238
  • 501

2 Answers2

0

It can't locate the Create action, make sure you are passing the right value for data-ajax-url.

You can use Html.Action herlper to create the url:

data-ajax-url="@(Html.Action("Create", "Submission"))"
LazZiya
  • 5,286
  • 2
  • 24
  • 37
0

Here is my working code:

<div>
<form method="get" data-ajax="true" data-ajax-url="/Submission/Create" data-ajax-method="get" data-ajax-update="#panel" data-ajax-failure="failed">
    <div class="form-group">
        <input type="submit" value="Submit" class="btn btn-primary" />
    </div>

</form>
</div>
@section Scripts {
  @{await Html.RenderPartialAsync("_ValidationScriptsPartial");
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-ajax-unobtrusive/3.2.6/jquery.unobtrusive-ajax.min.js"></script>

    <script>
        function failed() {

        }
    </script>
 }
}

Controller

public class SubmissionController : Controller
{
    public IActionResult Create()
    {
        return View();
    }
}

For your error, I think you can check if the url ‘/Submission/Create’ exists.And next you can check if there are some middlewares preventing from accessing to the url.

Xueli Chen
  • 11,987
  • 3
  • 25
  • 36