0

C#, .Net 4

Referring to XX1, XX2, XX3 below ( Under heading => Views: Main View {specifically @Html.ActionLink bit at the end}):

The object is initialized in the main controller. (The Person detial with child object (initialized in the Action Result )

I have added breakpoints at both XX1, etc. to confirm that that the initialized values are still there.

  • XX1, etc. have a problem. The initialized values are still there and is passed to, but a null object is somehow received by, the controller.

Why do the controller for the conflict of interest, etc. not pick up the parameters (_PersonCoi, not idx) passed to it.

Model:

public class CoiSPersonDetail
{
    public PersonDetail MyDetail { get; set; }
    public ConflictOfInterestPerson PersonSummary { get; set; }
}

public class ConflictOfInterestPerson
{
    public int Number { get; set; }
    public PersonDetail PersonDetailItem;
    public List<ConflictOfInterestItem> ConflictOfInterestList;
    public List<FinancialInterestItem> FinancialInterestList;
    public List<GiftInterestItem> GiftInterestList;
}

public class PersonDetail
{
    public int Number { get; set; }
    public string UserName { get; set; }
    public string Name { get; set; }
    public string Fullname { get; set; }
    public string Surname { get; set; }
    public Int64 ID { get; set; }
    public string Designation { get; set; }
    public int PeopleType { get; set; }
    public string PeopleLine { get; set; }
    public string PCUser { get; set; }
    public string PCUserManagement { get; set; }
    public string PCSearch { get; set; }
    public IEnumerable<SelectListItem> PersonDetailList { get; set; }
    public HttpPostedFileBase FileNameCOI { get; set; }
    public HttpPostedFileBase FileNameFin { get; set; }
    public HttpPostedFileBase FileNameGft { get; set; }
}

public class ConflictOfInterestItem
{
    public string Header { get; set; }
    public int ConflictID { get; set; }
    public int DeclarationID { get; set; }
    public int SectionID { get; set; }
    public int QuestionareID { get; set; }
    public string Question { get; set; }
    public bool SupportDocument { get; set; }
    public HttpPostedFileBase Document { get; set; }
    public bool Explain { get; set; }
    public bool YesNo { get; set; }
    public string Reason { get; set; }
    public Guid coiID { get; set; }
}

public class FinancialInterestItem
{
    [DisplayName("Name of Organisation")]
    public string Organization { get; set; }
    [DisplayName("Nature Of Interest")]
    public string NatureOfInterest { get; set; }
    [DisplayName("Date Of Acquisition")]
    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    public DateTime DateOfAcquisition { get; set; }
}

public class GiftInterestItem
{
    [DisplayName("Supplier of Gift")]
    public string Supplier { get; set; }
    [DisplayName("Recipient of Gift")]
    public string Recipient { get; set; }
    [DisplayName("Type of gift / entertainment")]
    public string Type { get; set; }
    [DisplayName("Estimated value")]
    public float EstimatedValue { get; set; }
    [DisplayName("Date received")]
    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    public DateTime DateReceived { get; set; }
    [DisplayName("Ultimate use")]
    public string UltimateUse { get; set; }
}

Controller:

For Main View

    public ActionResult Index(string Number, string Search, string Fullname, string Surname, string ID)
    {
        PersonDetail _MeCoI = new PersonDetail();
        ConflictOfInterestPerson _PersonCoI = new ConflictOfInterestPerson();

        _PersonCoI.PersonDetailItem = _db.ConflictOfInterestPerson(Number);

        _PersonCoI.Number = _PersonCoI.PersonDetailItem.Number;
        _PersonCoI.ConflictOfInterestList = _db.ConflictOfInterestList(_PersonCoI.Number.ToString());
        _PersonCoI.FinancialInterestList = _db.ConflictOfFinancialInterestList(_PersonCoI.Number.ToString(), _PersonCoI.ConflictOfInterestList.First().coiID);
        _PersonCoI.GiftInterestList = _db.ConflictOfGiftInterestList(_PersonCoI.Number.ToString(), _PersonCoI.ConflictOfInterestList.First().coiID);

        CoiSPersonDetail CoiSpd = new CoiSPersonDetail();
        CoiSpd.MyDetail = _MeCoI;
        CoiSpd.PersonSummary = _PersonCoI;
    }

For Other Views:

Conlfict of Interest (Controller):

    public ActionResult Form(ConflictOfInterestPerson _PersonCoI, string Idx)
    {
        //processing...

    }

Views:

**For Main View **

    @model ConflictOfInterest.Models.CoiSPersonDetail
    @{
        ViewBag.Title = "OverView";
    }

    @using (Html.BeginForm("Index", "Home"))
    {
        @Html.AntiForgeryToken()

        <h2>OverView</h2>
        <p>
        <!-- stuff -->
        </p>
        <strong>The Policy serves to provide guidance to all employees on:</strong>
        <ul>
            <li>what is a conflict of interest,</li>
            <li>how to avoid conflict of interest</li>
            <li>disclosing conflict of interest;</li>
            <li>managing conflict of interest; and</li>
            <li>disclosure of financial interest</li>
        </ul>
        <strong>What is a conflict of interest?</strong>
        <ul>
            <li><!-- stuff --></li>
            <li><!-- stuff --></li>
            <li><!-- stuff --></li>
            <li><!-- stuff --></li>

        </ul>
        <strong>The following forms are available to assist:</strong>
        <ul>
            <li><a href="@ViewBag.PathtoPolicy" target="_blank">Policy Document</a></li>
            <li>@Html.ActionLink("Conflict of Interest", "Form", "Home", new { _PersonCoI = Model.PersonSummary, idx = Model.PersonSummary.Number.ToString() }, null) </li> <!--XX1-->
            <li>@Html.ActionLink("Declaration", "FRADecInt", new { _PersonCoI = Model.PersonSummary })</li> <!--XX2-->
            <li>@Html.ActionLink("Gifts", "GiftDecInt", new { _PersonCoI = Model.PersonSummary })</li> <!--XX3-->
        </ul>
    }
  • `PersonSummary` is a complex object containing other complex objects and collections of complex objects. You cannot pass that model to the controller using `ActionLink()` You will need to pass something that identifies it and then get it from the repository in the controller method (refer also [this answer](http://stackoverflow.com/questions/28482103/how-to-work-with-routevalues-with-multiple-values-of-the-same-name/28582331#28582331) for an explanation of how it works) –  Oct 11 '16 at 09:08
  • Thank you. I would like to keep it in memory (not session variable {it expries after a while} and not save it to the database yet. Which kind of object do you suggest. – Danie Schoeman Oct 11 '16 at 09:12
  • If you want to ensure its not lost the you must save it somewhere (database, xml file etc) –  Oct 11 '16 at 09:15

0 Answers0