Asp.net mvc 编辑ActionLink的长度为14而不是用户ID?
在我的MVC应用程序(was MVC4/EF5)中的管理员用户视图之前,我使用轻松显示我的用户,并在模型上设置,以快速设置希望每个模型属性在网格中显示的方式 查看:Asp.net mvc 编辑ActionLink的长度为14而不是用户ID?,asp.net-mvc,entity-framework,asp.net-mvc-5,entity-framework-6,Asp.net Mvc,Entity Framework,Asp.net Mvc 5,Entity Framework 6,在我的MVC应用程序(was MVC4/EF5)中的管理员用户视图之前,我使用轻松显示我的用户,并在模型上设置,以快速设置希望每个模型属性在网格中显示的方式 查看: <!-- Grid.MVC Code -- Can no longer use with Auto-Generated ASP.Net IDENTITY properties--> <div> @*Images in Columns: https://gridmvc.codeplex.
<!-- Grid.MVC Code -- Can no longer use with Auto-Generated ASP.Net IDENTITY properties-->
<div>
@*Images in Columns: https://gridmvc.codeplex.com/discussions/440977*@
Html.Grid(Model).Columns(columns =>
{
//columns.Add().Encoded(false).Sanitized(false).SetWidth(30).RenderValueAs(o => @Html.CheckBox("checked", false));
columns.Add().Encoded(false).Sanitized(false).RenderValueAs(o => Html.ActionLink("Edit", "Edit", "UserManage", new { id = o.Id }, null));
columns.Add().Encoded(false).Sanitized(false).RenderValueAs(u => Html.ActionLink("Delete", "Delete", "UserManage", new { id = u.Id }, null));
columns.Insert(2, u => u.ProfilePictureUrl).Titled("User Img").Encoded(false).Sanitized(false).RenderValueAs(u => @<img class="" src="@u.ProfilePictureUrl" alt="Current Profile Image" width="75px" height="75px" />);
}).AutoGenerateColumns()
</div>
public class ApplicationUser : IdentityUser
{
// Setting GridColumn Annotations allows you to use AutoGenerateColumns on view to auto create the Grid based on the model. https://gridmvc.codeplex.com/
[Display(Name = "Name")]
[GridColumn(Title = "Name", SortEnabled = true, FilterEnabled = true, Width = "100")]
public string Name { get; set; }
[Display(Name = "Position")]
[GridColumn(Title = "Position", SortEnabled = true, FilterEnabled = true, Width = "50")]
public string Position { get; set; }
[NotMappedColumn]
public DateTime? RegisteredDate { get; set; }
在参加Microsoft TechED之后,在开发过程中转向MVC5/EF6是可行的,主要是为了利用。在新项目中,我复制了迄今为止完成的所有内容,我能够复制我对Grid.MVC的使用,但有一个小问题:新的ASP.Net有几个未在模型中明确列出的用户属性,这些属性也显示在我的Grid.MVC中,例如字段[PasswordHash]、[SecurityStamp]、[AccessFailedCount],更多信息请参见表[AspNetUsers]
由于这些标识属性不在我的模型中显式存在,因此我无法使用GridMvc.DataAnnotations将它们设置为[NotMappedColumn]
我的新视图代码如下所示:
@model IEnumerable<PROJECT.Models.ApplicationUser>
@{
ViewBag.Title = "View Users";
Layout = "MyLayout.cshtml";
}
<div class="row" id="submitRow">
<div class="btn-group ">
<a href="Create"><button type="submit" value="Create" class="btn btn-success">Create User</button></a>
</div>
</div>
<div class="overflowPrevention">
<table class="table">
<tr>
<th></th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
Img
</th>
<th>
Position
</th>
<th>
Registered
</th>
<th>
Last Visited
</th>
<th>
Email
</th>
<th>
Confirmed
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.ActionLink("Edit", "Edit", "UserManagement", new { id = item.Id }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProfilePictureSrc)
</td>
<td>
@Html.DisplayFor(modelItem => item.Position)
</td>
<td>
@Html.DisplayFor(modelItem => item.RegisteredDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastVisitDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmailConfirmed)
</td>
</tr>
}
</table>
有人对这件事有想法吗?
你打算做的是
[显示文本][操作方法][控制器][路由值]
但是,当我们查看4参数构造函数时,我们会看到:
ActionLink(HtmlHelper,String,String,Object,Object)
返回指定的链接文本、操作、路由值和HTML属性的锚元素(元素)
这不是你想要的。但是,这些字段:
ActionLink(HtmlHelper,String,String,String,Object,Object)
返回指定的链接文本、操作、控制器、路由值和HTML属性的锚元素(元素)
解决方案 改变这个
@Html.ActionLink("Edit", "Edit", "UserManagement", new { id = item.Id })
进入这个
@Html.ActionLink("Edit", "Edit", "UserManagement", new { id = item.Id }, null)
@Html.ActionLink("Edit", "Edit", "UserManagement", new { id = item.Id }, null)