I am building this page right here:
You can see, one item is selected and the button at the bottom (submit) is now clickable. This button
<div class="centered" style="padding-top: 50px;">
<input asp-page-handler="Button_Submit" style="width: 30% !important; opacity: 0.2; " value="Weiter" class="baseButton" type="submit" disabled="disabled">
</div>
fires this handler:
public async Task<IActionResult> OnPostButton_Submit(IFormCollection data)
{
return Page();
}
The items come from my model and get created like this:
<table class="table-fullWitdh" style="border-spacing: 13px">
@{
int counter = 0;
foreach (var elem in Model.ModelList)
{
if(counter % 7 == 0)
{
<tr >
@*every seventh item create new tr *@
</tr>
}
<td>
@*Item Template Start*@
<table class="itemBackgrond centered">
<tr>
<td>
<p>
@elem.Title
</p>
</td>
</tr>
<tr>
<td>
<img class="imgSmall" src="@elem.ImageSource" />
</td>
</tr>
</table>
@*Item Template End*@
</td>
counter++;
}
}
</table>
Now, when I click on one of the items I do some jquery to change the color and enable the button:
<script>
// click function on element. makes all other elements de
$(".itemBackgrond").click(function () {
$(".itemBackgrond").each(function () {
$(this).css("background-color", "#D8F1F0");
});
$(this).css("background-color", "#c3e1ed");
// also enable base button, doesnt need to be display
$('.baseButton').prop("disabled", false);
jQuery('.baseButton').css('opacity', '1');
});
</script>
SO I basically change the backgroudn color myself. However, when I now click on submit I still have no clue over what item was clicked (highlighted).
How can I retrieve the item with the altered background color inside my c# controller?
Thank you!
EDIT:****
I did find a workaround but that is hella complicated:
<table class="itemBackgrond centered" id="@elem.CategoryId"> @*give it id as cat name*@
<tr>
<td>
<p>
@elem.Title
</p>
<input style="display: none;" type="text" value="" name="selectedIdentifier" class="@elem.CategoryId" /> @*find class of that elem that belongs to table*@
</td>
</tr>
<tr>
<td>
<img class="imgSmall" src="@elem.ImageSource" />
</td>
</tr>
</table>
Basically, I put in there a hidden input element and add a class to it that has the same name as the ID of the model. Then in my jquery i do this:
var elem = $("." + this.id)
elem.val(this.id)
basically finding the class attached to that hidden element and add a the id to its value field.
In the controller i access all elements with that name:
var title = Request.Form["selectedIdentifier"];
which is one of my hidden inputs. But only the one with a value in it is returned and so I have my value inside my controller...
...