How do I use MVC3 editor templates for lists with add and delete?
I have an object:
public class Policy
{
public List<PolicyLine> PolicyLines = new List<PolicyLine>();
}
public class PolicyLine
{
public PolicyLine(bool isPositive, string policyText)
{
IsPositive = isPositive;
PolicyText = policyText;
}
public bool IsPositive { get; set; }
public string PolicyText { get; set; }
}
I have an editorTemplate: in Views\Shared\EditorTemplates\Policy.cshtml and Views\Shared\EditorTemplates\PolicyLine.cshmtml and I’m wondering how to enable users to add and delete PolicyLines from the Policy?
I got this to work for me:
Here is my Views/Policy/Index.cshtml
Here is my Views/Shared/EditorTemplates/Policy.cshtml
Here is my Views/Shared/EditorTemplates/PolicyLine.cshtml
Here is my Policy.cs
Here is my PolicyLine.cs
Here is my add method from PolicyController.cs
Here is my delete method from PolicyController.cs