Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

HttpPost Delete MVC for Composite Keys

$
0
0

I have a table with three columns with first two formulating the composite key

  1. SrcSys (CompositeKey Part I)
  2. CustId (CompositeKey Part II)
  3. CustNm

I am new to ASP & starting with MVC Core.

The following code for the delete's get method works well:

public async Task<IActionResult> Delete(string _SrcSys, string _CustId)
    {
        if (_SrcSys == null || _CustId == null)
        {
            return NotFound();
        }
        var customer = await _context.Customers.SingleOrDefaultAsync(Cust => Cust.SrcSys == _SrcSys && Cust.CustId == _CustId);
        if (customer == null)
        {
            return NotFound();
        }
        return View(customer);
    }

The relevant code of Delete.cshtml is:

@modelRiskDotNet.Models.Customer@{ViewData["Title"]="Delete";}<hr /><dl class="dl-horizontal"><dt>SrcSys</dt><dd>@Html.DisplayFor(model => model.SrcSys)</dd><dt>Cust ID</dt><dd>@Html.DisplayFor(model => model.CustId)</dd><dt>Customer</dt><dd>@Html.DisplayFor(model => model.CustNm)</dd></dl><form asp-action="Delete"><div class="form-actions no-color"><input type="submit" value="Delete"class="btn btn-default"/><p /><p /><input type="submit" value="Cancel"class="btn btn-default" a asp-action="Index"></div></form>

I need all the three fields to be appearing on the page, i.e. the Keys too and thats why I have added the same in the cshtml above.

In respect of the same what would be a change (if any) in Delete.cshtml and correct piece of code forHttpPost that you would recommend?

Thanks in advance.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>