Further to the solution that was suggested here: http://stackoverflow.com/a/28764650/4614348, which I tried but didn't work - I wanted to know how razor figures out to render a strongly typed partial view? I did what was suggested but it feels like it's not tied up properly and something is missing.

My "sub" model:

public class Cohort
    {
        public bool ukft { get; set; }
        public bool ukpt { get; set; }
        ...etc
    }

My strongly typed partial view:

@model Models.Cohort

@Html.RadioButtonFor(model => Model.ukft, true) <span style="margin-right:8px;">Yes</span>
@Html.RadioButtonFor(model => Model.ukft, false) <span>No</span> <br />

My main model (which contains a list of Cohort objects):

public class OptOut
    {
        public int optOutID { get; set; }
        public bool hasOptedOut { get; set; }        
        public List<Cohort> list { get; set; }

        public OptOut()
        {
            List<Cohort> list = new List<Cohort>();
            list.Add(new Cohort());
            list.Add(new Cohort());
            list.Add(new Cohort());
            list.Add(new Cohort());
            this.list = list;
        }

    }

and then my html:

@model Models.OptOut
@using (Html.BeginForm("OptedOut", "Home"))
        {   
            //this should supposedly figure out to render a partial view for each element in the list
            @Html.EditorFor(model => model.list)

            <div class="form-group" style="margin-top:25px;">
                <input id="confirm" type="submit" value="Confirm" class="btn btn-success btn-lg"/>
            </div>
        }

Related posts

Recent Viewed