0

Being battling this issue for too long now it's time to ask for help. The delete route of my .net core mvc app is not being hit. All other routes (Get, Post) are hit just fine. The route config at startup looks like this:

    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller}/{action}/{id?}");
    });

The form submit looks something like this:

    <a class="btn btn-primary" href="~/DisabledRegistrations/Delete/@(Model.Id)">Confirm</a>

The controller method looks like this:

[Authorize]
[HttpDelete]
public async Task<IActionResult> Delete(string id)
{
  ...
}

But hitting that with something like:

https://localhost:8307/DisabledRegistrations/Delete/f17dff6b3fcd43ba89eab4bbad5c992e

results in:

No webpage was found for the web address: 
https://localhost:8307/DisabledRegistrations/Delete/f17dff6b3fcd43ba89eab4bbad5c992e

We run in Service Fabric and not sure if there's any particulars to that. Our web.config has this although not sure if it's relevant in that context:

  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>

Any hints for things to try are greatly appreciated.

UPDATE:

If I actually do submit a form as follows:

<form asp-controller="DisabledRegistrations" asp-action="Delete" method="delete" asp-route-id="@Model.Id">
    <div class="text-right">
        <button type="submit" class="btn btn-primary">Confirm</button>
        <a class="btn btn-primary" href="~/DisabledRegistrations/Index">Cancel</a>
    </div>
</form>

Then I still get:

No webpage was found for the web address: 
https://localhost:8307/DisabledRegistrations/Delete/f17dff6b3fcd43ba89eab4bbad5c992e?__RequestVerificationToken=CfDJ8KwmDf2MXHlGrC8zIIntu4IV_83R9jSBwPqk3w8Ymq2VoBnQHN8lxEOHqMUfJwtxX-HLZwr6AWw8uKiVaSz7l-CZjPzZ_IxJhRh31MYiwbgsJzLcQMvrHWGd_sueZ8OLKbRAoYGeVHLfVfkjac-TCaLE9CoOYSCyhY4EDtrFhiLVY3_3h-bJTSLYTT2E7qXcvA
Tseng
  • 61,549
  • 15
  • 193
  • 205
webteckie
  • 428
  • 5
  • 17
  • is the submission using the DELETE verb? I don't think delete is valid for the method property of a form is it? – Mike_G Jan 04 '17 at 19:06
  • It shows up in VS as a valid option for the method attribute. – webteckie Jan 04 '17 at 19:12
  • yeah, I wouldn't trust that. Trust what the browser is telling you during request inspection: http://stackoverflow.com/questions/5162960/should-put-and-delete-be-used-in-forms – Mike_G Jan 04 '17 at 19:15
  • hmmm...you right, fiddler shows it doing a GET: GET /DisabledRegistrations/Delete/f17dff6b3fcd43ba89eab4bbad5c992e?... – webteckie Jan 04 '17 at 19:20
  • Got it working with a POST verb and Delete action. This will suffice for now. Thanks for the help! – webteckie Jan 04 '17 at 19:29

2 Answers2

1
[HttpDelete]

is a verb like post, you are not doing http delete from your link that is just doing http get therefore it doesn't match your route. to do delete verb you would have to use ajax and specify the verb.

you are not submitting a form, you only show an a element that links therefore get not delete verb

Joe Audette
  • 35,330
  • 11
  • 106
  • 99
  • My bad, I meant to include my form submit code as well (I've tried various ways) but missed that. I've updated the OP with that info. Still the same issue. – webteckie Jan 04 '17 at 19:00
  • I don't think web browsers support delete or put verbs in form method, so again you need ajax to do that, it isn't really using that verb therefore it doesn't match the route. You could change your Delete method to HttpPost and change the form method to post. but to use delete verb I think you would have to use ajax – Joe Audette Jan 04 '17 at 20:56
  • Thanks Joe, per my comment above below the OP that's what I've done. – webteckie Jan 04 '17 at 21:05
  • By using HTTP method transformation you can submit a form using POST that includes some special field specifying the actual method. A middleware then changes the method before it goes to MVC. But I consider that a bit of a hack and you really should be using POST if it is a form (and since this mutates data). – juunas Jan 04 '17 at 21:32
0

I am not entirely sure why you are using a form to do this. The < a> tag will do this for you very easily.

<div class="text-right">
    <a class="btn btn-primary" asp-controller="DisabledRegistrations" asp-action="Delete" asp-route-id="@Model.Id">Confirm</a>
    <a class="btn btn-primary" href="~/DisabledRegistrations/Index">Cancel</a>
</div>
Patrick Mcvay
  • 2,221
  • 1
  • 11
  • 22