TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Marius Vasile
590
1.9k
146.2k
ASP.NET Core Razor Post "Value" and "Text" from ddl
Jun 12 2020 2:53 AM
I want to update User Roles by using a select and post it to db. The select is working fine for RoleName but when I change or add a role, the RoleId has to be updated too. How do I do that in Razor pages?
With the below code only the RoleName is updated, for RoleId I get error because its valuue is null
UserRoleClassName = await _context.Roles.Select(a =>
new
SelectListItem
{
Value = a.Id.ToString(),
Text = a.Name
}).ToListAsync();
<div
class
=
"col-3"
>
<label
for
=
"RoleName"
>Role Name</label>
<select name=
"Role"
class
=
"form-control"
asp-
for
=
"AppIdentityRole.Role"
asp-items=
"Model.UserRoleClassName"
></select>
</div>
<input hidden name=
"RoleId"
asp-
for
=
"AppIdentityRole.RoleId"
class
=
"form-control"
value=
"@Model.UserRoleClassName"
/>
Reply
Answers (
1
)
how show multiple web pages on single web page
Populate duty roster using GridView in asp.net using c#