使用EditorForModel显示实体数据 [英] Displaying entities data with EditorForModel

查看:173
本文介绍了使用EditorForModel显示实体数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数据填充枚举器,我发送到视图,我渲染EditorForModel如下:

I've got data filled enumerator which I send to the view, I render the EditorForModel like this:

@model IEnumerable<TestProj.Models.Hours>
@Html.EditorForModel()

比EditorTemplates.Hours.cshtml: p>

than in the EditorTemplates.Hours.cshtml:

@model TestProj.Models.Hours
<div>
@Html.CheckBoxFor(
    x => x.Selected, 
    new { 
        @class = "jcf-unselectable",
        id = HtmlHelper.GenerateIdFromName("cb_slice." + ViewData.TemplateInfo.GetFullHtmlFieldName(""))
    }
)
@Html.LabelFor(x => x.SliceName)
</div>

当页面呈现时,我想显示所有SliceNames数据,而不是实体的名称SliceName 为标签显示。

When the page is rendered I want to show all the the SliceNames data , Not the entity's name "SliceName" for the labels display.

所以它将渲染复选框与标签与SliceName背后的数据。

So it will render the checkbox along with the label with the data behind SliceName.

我正在尝试这个选项,因为我已经理解使用循环的viewbags是不推荐的,但是我也想建议在EditorForModel范围之后。

I'm trying this option since I've understood using viewbags with loops ain't recommended, However I'd like suggestion behind the EditorForModel scope as well.

编辑:
如果我使用:

If I use :

@Html.DisplayTextFor(x => x.SliceName)

- 将数据放在SliceName后面(仅限文本)。

-Ill get the data behind SliceName (Text only).

如果我使用:

@Html.LabelFor(x => x.SliceName)

- 标签的文字标题SliceName。

-Ill get the title "SliceName" for the label's text.

如何使用@ Html.LabelFor获取数据作为文本像@ Html.DisplayTextFor?

How do I use @Html.LabelFor to get the data as text like @Html.DisplayTextFor?

推荐答案

听起来像你可能哈您的表单有问题。

It sounds like you may have a problem with your Form.

如果您这样做:

@Html.BeginForm()
{
...
}

而不是这样:

@using(Html.BeginForm())
{
...
}

您的Model的名称将会显示,而不是Model的值。

The names of your Model will appear instead of the values of the Model.

这篇关于使用EditorForModel显示实体数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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