MVC 3-List<>的编辑器模板模型 [英] MVC 3 - Editor template for List<> Model

查看:79
本文介绍了MVC 3-List<>的编辑器模板模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建我的第一个Razor应用程序,并且非常喜欢它.我正在尝试介绍如何创建一个编辑器模板,该模板可以呈现出一个可编辑的项目列表,而无需foreach循环.这可能吗?

I am building my first Razor app and really loving it. I am trying to get the low-down on how to create an editor template that renders out an editable list of items without a foreach loop. Is this possible?

以下是我要实现的目标的基本知识:

Here are the basics of what I am trying to achieve:

在我看来(Views/Image/Homepage.cshtml),我拥有:

In my view (Views/Image/Homepage.cshtml) I have:

@model List<MyNameSpace.Image>

@{
    ViewBag.Title = "Homepage Images";
}

@*????*@
@Html.EditorFor(Model => Model)

在我的编辑器模板(Views/Image/EditorTemplates/Image.cshtml ??)中,我有:

And in my editor template (Views/Image/EditorTemplates/Image.cshtml??) I have:

@model MyNameSpace.Image

<div>@Html.TextBoxFor(Model => Model.Title)</div>
<div>@Html.TextBoxFor(Model => Model.LongDescription)</div>

推荐答案

大声笑这很尴尬,但值得一提,上面的代码运行良好,我在控制器中创建了一个测试列表,但忘了将其传递给视图:- D

LOL this is embarrassing but worthy of mentioning, the code above works fine, I created a test list in the controller but forgot to pass it to the view :-D

这篇关于MVC 3-List&lt;&gt;的编辑器模板模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆