【问题标题】:asp.net mvc editor template is not called and displaying text未调用 asp.net mvc 编辑器模板并显示文本
【发布时间】:2015-10-28 14:11:14
【问题描述】:

这是我的方法

  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);
    }

这是我的模型

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

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

这是我的看法Index

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


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

这是我的部分观点EditableContent

@model WebApplication6.Models.EditableContent

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

现在当我渲染索引页面时,它显示 sss , fff 并且它不调用模板代码?可能是什么问题

【问题讨论】:

    标签: c# asp.net asp.net-mvc asp.net-mvc-4 razor


    【解决方案1】:

    需要在以下文件夹结构Views/EditorTemplates/EditableContent.cshtml中创建部分。

    画面输出

    【讨论】:

    • 好的,但很奇怪,我觉得它会自行迭代coding-in.net/asp-net-mvc-3-how-to-use-editortemplates,我在这里也读了一两个答案
    • 好的,我想在 editortemplates 文件夹中创建它,但不需要迭代,这就是问题所在
    • @maz3tt 不错,我更新了答案以反映这一点。 :)
    猜你喜欢
    • 2011-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多