问题描述
删除记录后,navigate.manager不起作用
我试图删除记录,然后在此页面上移动(https:// localhost:44399 / DisplayEmployeeData)
我的记录已成功删除,但请注意导航并给出错误消息
客户端:
DeleteEmployee.razor
@using CrudBlazorServerApp.Data
@page "/DeleteEmployee/{id}"
@inject HttpClient Http
@using System.Net.Http
@inject NavigationManager navigationManager
<h3>DeleteEmployee</h3>
<div class="row">
<div class="col-md-4">
@if (emp != null)
{
<form>
<div class="form-group">
<label for="username" class="control-label">username:</label>
@emp.username
</div>
<div class="form-group">
<label asp-for="empaddress" class="control-label">empaddress:</label>
@emp.empaddress
</div>
<div class=" form-group">
<label asp-for="password" class="control-label">password:</label>
@emp.password
</div>
<div class=" form-group">
<label asp-for="country" class="control-label">country:</label>
@emp.country
</div>
<div class="form-group">
<button @onclick="Delete">Delete</button>
</div>
</form>
}
</div>
</div>
@code {
[Parameter]
public string Id { get; set; }
Emp emp;
protected override async Task OnInitializedAsync() =>
emp = await Http.GetFromJsonAsync<Emp>("https://localhost:44333/api/emps/getemp/" + Id);
private async Task Delete()
{
@if (Id != null)
{
string url = "https://localhost:44333/api/emps/checkDelete?empid=" + Id;
await Http.GetFromJsonAsync<Emp>(url);
navigationManager.NavigateTo("https://localhost:44399/DisplayEmployeeData"); //here I am facing issue not navigate
}
}
}
ServerSide(WebApi):
EmpsController.cs
[HttpGet]
public Emp checkDelete(int empid,string username,string empaddress,string password,string country)
{
var deletercord = _context.emps
.Where(s => s.empid == empid)
.FirstOrDefault();
deletercord.username = username;
deletercord.empaddress = empaddress;
deletercord.password = password;
deletercord.country = country;
_context.emps.Remove(deletercord);
_context.SaveChanges();
return deletercord;
}
我想当用户按下Delete键然后浏览页面
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)