C
C#2w ago
morry329#

Id points to always null

I have an Edit method which always returns a null id: https://pastecode.io/s/upokmghg I tried to map the Id (from the controller/model) on my cshtml but it did not help. Could anyone kindly point me in the right direction??
5 Replies
Angius
Angius2w ago
You have no form field with the name id
morry329#
morry329#OP2w ago
Could you kindly point me what went wrong here .. I mean I tried to map the controller to the cshtml but the id is still null at my controller My controller https://pastebin.com/cSzKufsU My cshtml https://pastebin.com/rwqSwMV2 <--- I even created a form tag to mark the form field with the same Id in controller. Still none of these helped
Pastebin
public async Task EditListingJpost([FromForm]int? editSubmitId) //...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Angius
Angius2w ago
The type of this input is text, while the controller expects an integer
morry329#
morry329#OP2w ago
Could you kindly point out which type in which input exactly you mean ? Please just point out which line out of the following cshtml
<div id="EditDashboardNow" method="post" name="editSubmitId">
<form method="post" asp-route="Form" id="editSubmitId" name="editSubmitId">
@using (Html.BeginForm("EditListingJpost", "Home", FormMethod.Post, new { @class = "ListingProjectsDTO", @id = "MyId", enctype = "multipart/form-data" }))
{
<div class="listing form-horizontal">
<div><img class="listingPhoto" src="~/imgSearchHome/IMG_20220102_161928.jpg"/></div>
<div class="content">
<input type="hidden" id="EditIdButHidden" name="EditIdButHidden"/>
<input type="hidden" id="editPropertyName" name="editPropertyName"/>
<p>Property Name:
<div class="form-group">
<input class="form-control" type="text" id="editPropertyName" name="editSubmitId"/>
<p>try this form also</p>
<input class="form-control" type="text" name="editSubmitId"/>
</div>
<picture>I am the EditDashboard now</picture>
</p>

<div>
<button type="button" id="btnSaveEdit" value="Save" onclick="EditListingJpost(@listingMd.Id)">Save</button>

<div id="EditDashboardNow" method="post" name="editSubmitId">
<form method="post" asp-route="Form" id="editSubmitId" name="editSubmitId">
@using (Html.BeginForm("EditListingJpost", "Home", FormMethod.Post, new { @class = "ListingProjectsDTO", @id = "MyId", enctype = "multipart/form-data" }))
{
<div class="listing form-horizontal">
<div><img class="listingPhoto" src="~/imgSearchHome/IMG_20220102_161928.jpg"/></div>
<div class="content">
<input type="hidden" id="EditIdButHidden" name="EditIdButHidden"/>
<input type="hidden" id="editPropertyName" name="editPropertyName"/>
<p>Property Name:
<div class="form-group">
<input class="form-control" type="text" id="editPropertyName" name="editSubmitId"/>
<p>try this form also</p>
<input class="form-control" type="text" name="editSubmitId"/>
</div>
<picture>I am the EditDashboard now</picture>
</p>

<div>
<button type="button" id="btnSaveEdit" value="Save" onclick="EditListingJpost(@listingMd.Id)">Save</button>

`
Angius
Angius2w ago
Let's see... 1. You posted code where you had an id parameter in the controller, and no name="id" input in the form 2. You fixed that naming issue by renaming the parameter to editSubmitId to match the form input name="editSubmitId" 3. I said that the input is of type="text" while the parameter is an int? Which, pray tell, input could I have in mind?

Did you find this page helpful?