I tried your code from the github and I could not reproduce your problem since you embedded the number "1,2,3" to pass the parameter "heroId".
Hence, the "edit undefined" error could not occur from my side.
However, there are two errors in the function "putHero" in service.js file that may fails you.
1.You should assign the updated value to the corresponding field for updateHero variable. However, you just simply assign them to updateHero variable
2.You are wrongly using the selector for the update input field because you named the input field with name without the capital letter "U". Instead, you should select the html element by "#updateFirstname" for
instance.
What's more, you constructed the data model "SuperHero" with the property "Id" but what I can see is that you are access "id" for a "hero" instance in the code.
You have to polish the code especially for spelling error there.
Hope this can help you.
Best regards,
Sean
ASP.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
Contributor
3010 Points
886 Posts
Re: Update function throwing error!
Mar 19, 2020 07:24 AM|Sean Fang|LINK
Hi, Markus33,
I tried your code from the github and I could not reproduce your problem since you embedded the number "1,2,3" to pass the parameter "heroId".
Hence, the "edit undefined" error could not occur from my side.
However, there are two errors in the function "putHero" in service.js file that may fails you.
1.You should assign the updated value to the corresponding field for updateHero variable. However, you just simply assign them to updateHero variable
2.You are wrongly using the selector for the update input field because you named the input field with name without the capital letter "U". Instead, you should select the html element by "#updateFirstname" for instance.
After Update code:
function putHero() { updateHero['FirstName'] = $("#updateFirstname").val(); updateHero['LastName'] = $("#updateLastname").val(); updateHero['HeroName'] = $("#updateHeroname").val(); updateHero['PlaceOfBirth'] = $("#updatePlaceOfBirth").val(); updateHero['Combat'] = $("#updateCombatPoints").val(); $.ajax({ url: "Service/SuperHeroService.svc/UpdateHero/" + updateHero.Id, type: "PUT", datatype: "json", contentType: "application/json", data: JSON.stringify(updateHero), success: function () { showOverview(); } }); }
Demo:
What's more, you constructed the data model "SuperHero" with the property "Id" but what I can see is that you are access "id" for a "hero" instance in the code.
You have to polish the code especially for spelling error there.
Hope this can help you.
Best regards,
Sean