1

私の削除ビューは次のようなものです:

@model Pdsl.Sms.Entities.Models.Common.BranchInfo

@{
ViewBag.Title = "Delete";
Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Delete</h2>

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

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

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

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

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

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

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

<div>
    @Html.Partial("Delete_ContactDetailPartialView", Model.ContactDetails) 
   //partial view
</div>

</fieldset>
@using (Html.BeginForm()) {
<p>
    <input type="submit" value="Delete" /> |
    @Html.ActionLink("Back to List", "Index")
</p>
}

コントローラーでの私のアクションは次のようになります。

    private long cDetailId;
    public ActionResult Delete(int id)
    {
        BranchInfo branchInfo = branchInfoService.getABrachInfo(id);
        if (branchInfo == null)
        {
            return HttpNotFound();
        }

        cDetailId = (long)branchInfo.ContactDetailId;
        branchInfo.ContactDetails = contactDetailService.getAContactDetails(cDetailId);

        return View(branchInfo);
    }

    [HttpPost, ActionName("Delete")]
    public ActionResult DeleteConfirmed(int id)
    {
        try
        {
            branchInfoService.deleteBranchInfo(id);
            contactDetailService.deleteContactDetail(cDetailId);

            return RedirectToAction("Index");
        }
        catch
        {
            return View();
        }
    }

削除確認はきちんと表示されています。しかし、削除ボタンをクリックすると、次のエラーが表示されます。

Object reference not set to an instance of an object.

    Line 55:     
    Line 56:     <div>
    Line 57:         @Html.Partial("Delete_ContactDetailPartialView", Model.ContactDetails)
    Line 58:     </div>
    Line 59:
4

1 に答える 1