下面是我的控制器和视图的摘要。我想从视图中调用 GetUserDistinguished 方法。这只是化妆品。Guid 很丑陋,对最终用户没有意义,但它是我为用户使用的唯一 ID。
namespace Users.Controllers
{
public class UsersController : Controller
{
public ViewResult Index()
{
var users = db.Users.Include("Users");
return View(users.ToList());
}
public string GetUserDistinguished(string Guid)
{
return ADHelper.ConvertGuidToDn(Guid);
}
}
}
@model IEnumerable<Test.GuidToDistinguishedName>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
Name from Guid
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Guid)
</td>
</tr>
}
</table>