我包括以下行以使用IdentityRole预定义表,该表包含Name和ID字段。
@model IEnumerable<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>
由于无法识别在IdentityRole类中存在的model.Name,我不断收到许多错误。
我得到的错误是:
Severity Code Description Project File Line Suppression State
Error CS0411 The type arguments for method 'LabelExtensions.LabelFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, object)' cannot be inferred from the usage. Try specifying the type arguments explicitly. 13_Views_Roles_Create.cshtml C:\Users\xxx\Desktop\xxxxV2\JobBoardSystem\Views\Roles\Create.cshtml 20 Active
Severity Code Description Project File Line Suppression State
Error CS0411 The type arguments for method 'ValidationExtensions.ValidationMessageFor<TModel, TProperty>(HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, string, object)' cannot be inferred from the usage. Try specifying the type arguments explicitly. 13_Views_Roles_Create.cshtml C:\Users\xxxx\Desktop\JobBoardSystem V2\xxxx\Views\Roles\Create.cshtml 23 Active
代码如下:
@model IEnumerable<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>RoleViewModel</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
答案 0 :(得分:1)
创建页面通常不处理列表,仅处理单个模型项。您的模型应为
@model Microsoft.AspNet.Identity.EntityFramework.IdentityRole