Last post Oct 21, 2020 02:30 AM by Amplitude
Oct 20, 2020 07:18 PM|Amplitude|LINK
Is it possible to have a method in your controller that you can call to do something operational, like say, delete records from the database but stay on the same view without needing to create an extra view?
I have the following method:
public void DoSomeStuff(int id)
// do stuff here
I want to click a button on the current view to call the above method:
However, if I did something like this, it will require a view:
<a asp-controller="Customer" asp-action="DoSomeStuff" asp-route-id="@customer.CustomerId">Do Something</a>
In a nut shell, how can I call a controller method without the need for a new view?
Oct 21, 2020 01:53 AM|bruce (sqlwork.com)|LINK
Oct 21, 2020 02:01 AM|Jerry Cai|LINK
like say, delete records from the database but stay on the same view without needing to create an extra view?
You can redirect to the current view when delete the records, you can check my following demo, it just need one index view:
public IActionResult Index()
var model = _db.Students.ToList();
public async Task<IActionResult> Delete(int id)
var stu = await _db.Students.FindAsync(id);
@Html.DisplayNameFor(model => model.name)
@foreach (var item in Model)
@Html.DisplayFor(modelItem => item.name)
<form asp-action="Delete" asp-route-id="@item.Id">
<input type="submit" value="Delete" class="btn btn-danger" />
Oct 21, 2020 02:30 AM|Amplitude|LINK
Thanks so much Jerry!