0
我正在使用asp.net創建一個網站。
我第一次創造了一些模型,這就是其中之一:我如何在Razor中使用幫助函數?
public class User
{
[Key]
public int UserID { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public virtual ICollection<Subscription> Subscriptions { get; set; }
}
然後,我創建了一些強類型的意見,其中之一是這樣的:
@model IEnumerable<Liquidity_Web.Models.User>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.UserName)
</th>
<th>
@Html.DisplayNameFor(model => model.Password)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.UserName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Password)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.UserID }) |
@Html.ActionLink("Details", "Details", new { id=item.UserID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.UserID })
</td>
</tr>
}
</table>
然而,這
@Html.DisplayNameFor(model => model.UserName)
會給我"UserName"
的意見。我想要顯示"User Name"
(用空格分隔)。
我有一個輔助功能
public List<string> SplitHelper(string target);
但如何使用剃刀視圖內?我試圖
@Html.DisplayNameFor(model => StringSplit(model.UserName))
,但它不工作..
我也覺得間隔出字符串不應意見的責任。但是我應該在哪裏以及如何做到這一點?
謝謝,這正是我要找的。 – octref
OP:請將此答覆標記爲已接受的答案。 – Rob