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
592
1.9k
146k
ASP.NET Core Razor - Post input, variable and string values
May 31 2020 9:38 AM
I am trying to save to table three values, one coming from cshtml input
<div
class
=
"col-2"
>
<select
class
=
"form-control border-warning"
style=
"font-size:12px"
asp-
for
=
"PTWContent.PTWType"
asp-items=
"Html.GetEnumSelectList<RoSafety.Models.PTW.PTWType>()"
>
<option value=
""
>Permit to Work Type</option>
</select>
<span asp-validation-
for
=
"PTWContent.PTWType"
class
=
"text-danger"
></span>
</div>
one from a variable and one string from cshtml.cs
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
var addPTW =
new
PTWContent();
if
(await TryUpdateModelAsync(addPTW,
"PTWContent"
, s => s.PTWType, s => s.UserID == userId, s => s.WorkComplete ==
"No"
))
{
_context.PTWContents.Add(addPTW);
await _context.SaveChangesAsync();
return
RedirectToPage(
"./PTW"
);
}
The error I get is
An unhandled exception occurred while processing the request.
InvalidOperationException: The passed expression of expression node type 'Equal' is invalid. Only simple member access expressions for model properties are supported.
Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingHelper.GetPropertyName(Expression expression)
Reply
Answers (
3
)
Getting error "Lambda expression used inside Include is not"
how to save date and time in db at the time of form submissi