MVC 索引视图中的字符到枚举
我的数据库中有帮助框。这些是人们在网站上收到的消息。每条消息都有一个接收者。要么是组织,要么是用户,或者两者兼而有之。
有这个枚举
public enum Ontvangers {
All = 'A',
Organisation = 'I',
User = 'D'
}
我的索引视图中现在
public ActionResult Index(string schooljaarparam) {
var boxes = _db.HelpBoxes.Where(q => q.Schooljaar.Sch_Schooljaar == schooljaarparam);
return View(boxes);
}
,
<% foreach (var item in Model) { %>
<tr>
<td>
<%: Html.ActionLink("Edit", "Edit", new { id=item.hlpb_ID }) %> |
<%: Html.ActionLink("Details", "Details", new { id=item.hlpb_ID })%> |
<%: Html.ActionLink("Delete", "Delete", new { id=item.hlpb_ID })%>
</td>
<td>
<%: item.hlpb_Titel %>
</td>
<td>
<%: item.hlpb_Schooljaar %>
</td>
<td>
<%: item.hlpb_Ontvanger %>
</td>
<td>
<%: item.SiteMap.Title %>
</td>
</tr>
<% } %>
我只能看到 A、I 或 D。现在我想显示用户、组织或全部,
如何在那里获取该值?我可能需要使用扩展,但我对枚举不是很熟悉。一些建议将不胜感激。
编辑:
它可以工作,但它并不漂亮:)我想把它放在一个助手中,但是如何......
<td>
<%: Enum.GetName(typeof(MVC2_NASTEST.Controllers.HelpBoxController.Ontvangers),(int)char.Parse(item.hlpb_Ontvanger.Trim())) %>
</td>
I have HelpBoxes in my DB. those are messages people get on the site. each message has a receiver. either it's an organisation or a user, or both.
I have this Enum
public enum Ontvangers {
All = 'A',
Organisation = 'I',
User = 'D'
}
now in my index view
public ActionResult Index(string schooljaarparam) {
var boxes = _db.HelpBoxes.Where(q => q.Schooljaar.Sch_Schooljaar == schooljaarparam);
return View(boxes);
}
and
<% foreach (var item in Model) { %>
<tr>
<td>
<%: Html.ActionLink("Edit", "Edit", new { id=item.hlpb_ID }) %> |
<%: Html.ActionLink("Details", "Details", new { id=item.hlpb_ID })%> |
<%: Html.ActionLink("Delete", "Delete", new { id=item.hlpb_ID })%>
</td>
<td>
<%: item.hlpb_Titel %>
</td>
<td>
<%: item.hlpb_Schooljaar %>
</td>
<td>
<%: item.hlpb_Ontvanger %>
</td>
<td>
<%: item.SiteMap.Title %>
</td>
</tr>
<% } %>
I get only to see the A, I or D. now I want to show User, Organisation or All
How do I get that value there? I probably need to use an extension but I am not very familiar with Enum's. Some advice would be appreciated.
edit:
it works, but it aint pretty :) I would like to put it in a helper, but how...
<td>
<%: Enum.GetName(typeof(MVC2_NASTEST.Controllers.HelpBoxController.Ontvangers),(int)char.Parse(item.hlpb_Ontvanger.Trim())) %>
</td>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从值获取枚举名称:
You can get enum name from value:
试试这个:
Try this: