I want to edit blogs but my ViewModel can't get CategoryId
and BlogId
.
This is the edit view:
I can get other data for example Title
, Description
but CategoryId
returns 0.
This is BlogEditVM:
If you need more details I can edit my post, thanks.
CodePudding user response:
You are passing the CategoryId
value as Category.CategoryId
to API action. Hence, you cannot get the CategoryId
value from the BlogEditVM
object in the API action.
You need to specify the name
attribute in the <select>
element as below:
<select asp-items="@ViewBag.values"
asp-for="@Model.Category.CategoryId"
name="CategoryId">
...
</select>