maztt
maztt

Reputation: 12294

asp.net mvc editor template is not called and displaying text

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

Upvotes: 2

Views: 80

Answers (1)

hutchonoid
hutchonoid

Reputation: 33305

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

Screen output

Screen output

Upvotes: 2

Related Questions