Reputation: 65
I have included the following line to use IdentityRole predefined table which contains Name and ID field.
@model IEnumerable<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>
I keep getting a number of errors for not recognizing the model.Name which exists at the class IdentityRole.
The errors that I am getting is:
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
The code is the following:
@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")
}
Upvotes: 1
Views: 543
Reputation: 785
The create page usually doesn't deal with a list, just with a single model item. Your model should be
@model Microsoft.AspNet.Identity.EntityFramework.IdentityRole
Upvotes: 1