2

Here is my method

  public ActionResult Index()
    {
        var viewModel = new Page();

        var content = new EditableContent { SidebarRight = "sss", SidebarLeft = "fff" };

        var content1 = new EditableContent { SidebarRight = "fff", SidebarLeft = "fggggg" };
        var Contents= new List<EditableContent>{ content , content1 };
        viewModel.Content = Contents;

        return View(viewModel);
    }

Here is my model

   public class EditableContent
{
    public string SidebarLeft { get; set; }
    public string SidebarRight { get; set; }
}

public class Page
{
    public List<EditableContent> Content { get; set; }
}

here is my view Index

@model WebApplication6.Models.Page
@{
    ViewBag.Title = "Index";
}


@using (Html.BeginForm())
{   
    @Html.EditorFor(page => page.Content, "Content")  
    <input type="submit" value="create" />
}

Here is my partial view EditableContent

@model WebApplication6.Models.EditableContent

@Html.TextBoxFor(m => m.SidebarLeft)<br />
@Html.TextBoxFor(m => m.SidebarRight)

now when i render the Index page it displayed sss , fff and it doesn't call the template code? what might be the issue

1 Answer 1

2

The partial needs to be created within the following folder structure Views/EditorTemplates/EditableContent.cshtml.

Screen output

Screen output

Sign up to request clarification or add additional context in comments.

3 Comments

ok it works but strange i had the impression that it iterates by itself coding-in.net/asp-net-mvc-3-how-to-use-editortemplates , i read one or two answers here as well
ok i miss creating it in editortemplates folder, but iterating is not required and that was the problem
@maz3tt Nice one, I updated the answer to reflect that. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.