I made an action to delete and delete, but in View delete does not appear the value of the field, which comes from the model. This is cshtml:
@model TreinamentoCrud.Models.Cidade
@{
ViewBag.Title = "Delete";
}
<h2>Delete</h2>
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>Cidade</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.nome)
</dt>
<dd>
@Html.DisplayFor(model => model.nome)
</dd>
</dl>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
<div class="form-actions no-color">
<input type="submit" value="Delete" class="btn btn-default" /> |
@Html.ActionLink("Voltar", "Index")
</div>
}
</div>
and this is the controller
public async Task<ActionResult> Delete(int id)
{
DeleteCidadeAsync deleteCidade = new DeleteCidadeAsync();
await deleteCidade.DeleteCidade(id);
return View();
}
However delete, the attribute in the method is like [HttpPost] . Is this normal? See in this screenshot what I am saying
SeethattheNamepropertyisemptyandshouldappearLosAngeles
EDIT1
Ididthatanditcontinuesthesamething
[HttpGet]publicasyncTask<ActionResult>Delete(intid){GetCidadesAsynccidade=newGetCidadesAsync();varmodel=awaitcidade.GetCidades();returnView();}//POST:Cidade/Delete/5[HttpPost]publicasyncTask<ActionResult>Delete(intid,Cidadecidade){try{DeleteCidadeAsyncdeleteCidade=newDeleteCidadeAsync();awaitdeleteCidade.DeleteCidade(id,cidade);returnRedirectToAction("Index");
}
catch
{
return View();
}
}
My method is like this now
public class DeleteCidadeAsync
{
HttpClient client = new HttpClient();
public async Task DeleteCidade(int id, Cidade cidade)
{
string url = $"http://localhost:56137/api/DeleteCidade/{id}";
await client.DeleteAsync(url);
}
}
See that way and the previous one, both are deleting. It just does not show the name of the face to be deleted.