Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6700325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:48:03+00:00 2026-05-26T06:48:03+00:00

How do I use MVC3 editor templates for lists with add and delete? I

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:48:03+00:00Added an answer on May 26, 2026 at 6:48 am

    I got this to work for me:

    Here is my Views/Policy/Index.cshtml

    @using (Html.BeginForm("Submit", "Policy")) {
    <fieldset>
    @Html.EditorForModel()
    </fieldset>
    }
    

    Here is my Views/Shared/EditorTemplates/Policy.cshtml

    @model Policy
    <br />
    <label for="IsPositive">Is positive?</label>
    @Html.CheckBox("IsPositive")
    <input type="text" name="PolicyText" />
    <input type="submit" value="Add to Policy"  title="SubmitFromReferalPolicy" />
    @Html.EditorFor(a => a.PolicyLines)
    

    Here is my Views/Shared/EditorTemplates/PolicyLine.cshtml

    @model PolicyLine
    <br />
    @this.Model.ToString()
    @Html.ActionLink("Delete", "DeleteLine/" + Model.Identifier.ToString())
    

    Here is my Policy.cs

    public class Policy
    {
        public string Id { get; set; }
    
        public List<PolicyLine> PolicyLines = new List<PolicyLine>();
    
        public override string ToString()
        {
            return PolicyFormatter.FormatPolicy(this);
        }
    }
    

    Here is my PolicyLine.cs

    public class PolicyLine
    {
        public bool IsPositive { get; set; }
    
        public string PolicyText { get; set; }
    
        public Guid Identifier { get; set; }
    
        public override string ToString()
        {
            return PolicyFormatter.FormatPolicyLine(this);
        }
    }
    

    Here is my add method from PolicyController.cs

        [HttpPost]
        public ActionResult Submit(PolicyLine submitted)
        {
            Policy saveMe = Policy.GetPolicyFromUserName(UserName);
            submitted.Identifier = Guid.NewGuid();
            saveMe.PolicyLines.Add(submitted);
            Store.Write(saveMe);
    
            return RedirectToAction("Index");
        }
    

    Here is my delete method from PolicyController.cs

        public ActionResult DeleteLine(Guid identifier)
        {
            Policy saveMe = Policy.GetPolicyFromUserName(UserName);
            PolicyLine removeMe = saveMe.PolicyLines.Find(p => p.Identifier == identifier);
            saveMe.PolicyLines.Remove(removeMe);
            Store.Write(saveMe);
            return RedirectToAction("Index");
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Spring MVC 3.0 and JSP. I have an object: public class ObjectWrapper
I have a register form created by mvc3 scaffolding. e.g. <div class=editor-label> @Html.LabelFor(model =>
I am building an asp.net mvc3 application and I have decided to use areas
I have an MVC3 application, I know that for relative paths, I can use
I have developed a MVC3 application in that I want use the Check boxlist
I use Jquery Autocomplete in my mvc3 application. I have a lot of textbox,
use Rack::Static, :urls => ['/stylesheets', '/images'], :root => 'public' run proc { |env| [200,
Bear with me as I describe the issue. An MVC3 application making use of
I'm building a website using MVC3, EF, and Razor and I currently have the
I just started to use the routes in MVC3 and I am totally confused.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.