How does the Controller know Id on DeleteConfirmed in MVC?

Hi, can anyone explain how the default removal method created by Visual Studio works. I am confused because when you submit DeleteConfirmed, the model Idis passed back to the controller. But there is no field in the view that was not Ideven created in the hidden field, since Id/ reset in the column is not lost? How does the controller know Id?

View

   @{
        ViewBag.Title = "Delete";
    }

<h2>Delete</h2>

<h3>Are you sure you want to delete this?</h3>
<fieldset>
    <legend>SellersQuery</legend>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Name)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Name)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Manufacturer)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Manufacturer)
    </div>
</fieldset>
@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    <p>
        <input type="submit" value="Delete" /> |
        @Html.ActionLink("Back to List", "Index")
    </p>
}

controller

public ActionResult Delete(int id = 0)
        {
            SellersQuery sellersquery = db.SellerQuerySet.Find(id);
            if (sellersquery == null)
            {
                return HttpNotFound();
            }
            return View(sellersquery);
        }

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            SellersQuery sellersquery = db.SellerQuerySet.Find(id);
            db.SellerQuerySet.Remove(sellersquery);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
+4
source share
2 answers

URL GET Delete, , - /Controller/Action/Id. , ID , ID URL- ID .

+3

, , , - _/Delete/Id, , .

0

All Articles