无法找到资源。无法点击网址

问题描述 投票:0回答:1

错误信息:

 The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

请求的网址:/Receivers/Create

我在Receivers Folder中创建了视图。我检查了拼写。它是正确的但创建页面没有显示。

代码如下。

@model IEnumerable<BBProjectnew.Models.Receivers.Receiver>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>

我的控制器代码如下。

    [HttpPost]
            [ValidateAntiForgeryToken]
            public async Task<ActionResult> Create(ReceiverCreationModel model)
            {
                if (ModelState.IsValid)
                {
                    await receiverService.CreateReceiver(model);
                }

                return RedirectToAction("Index");
            }

我的ReceiverService代码如下

public async Task CreateReceiver(ReceiverCreationModel model)
            {
                DbContext.Receivers.Add(Mapper.Map<ReceiverCreationModel, Receiver>(model));
                await DbContext.SaveChangesAsync();
            }

            public Receiver ReceiverDetails(int id)
            {
                return DbContext.Receivers.SingleOrDefault(d => d.ReceiverId == id);
            }
c# asp.net asp.net-mvc visual-studio
1个回答
0
投票

你不能使用Html.ActionLink来调用post动作方法(见下面的链接)。你可以使用@Ajax.ActionLink(... new AjaxOptions { HttpMethod = "POST" }) instaed。

Sending Html.ActionLink to post action

**编辑另一种选择是使用Html.BeginForm

Html.BeginForm("ActionName", "ControllerName", null, FormMethod.Post, new { your arguments })
© www.soinside.com 2019 - 2024. All rights reserved.