Hi I am new to MVC and I have hidden fields that are populated through jQuery on a checkbox change event.
Is it possible to then get this value and use it in an MVC @Html.ActionLink
?
Sample code:
<div class="col-md-3" style="text-align: center;">
<label style="text-decoration: underline;">Quote 3</label>
<br />
<label id="lblQuote3"></label>
<input type="hidden" id="hdfQuote3" />
</div>
<div class="col-md-3 compareButtonDiv" style="text-align: center;">
@Html.ActionLinkNonEncoded("Compare Risks", "CompareRisks", "Lead", routeValues: new { bid = @Request.QueryString.Get("bid") }, htmlAttributes: new { @class = "btn btn-primary btn-md", @title = "Compare Risks" })
</div>
I am trying to get the value from the hidden field lblQuote3
and send that value to the controller. I think to send the value I include it in the rootValues
.
After taking advice from Stephen Muecke I was able to build a solution to my problem.
On my page, I have dynamically added checkboxes that when their checked property changes a function is called to either add or remove text to/from a
<label>
.This text was then to be added to, or removed from, the
href
of abutton
.The solution I came up with was to write a couple of functions that handle all the logic I require.
Checkbox On Change event:
Functions called:
When a checked box is checked it call on,
function checkAndStoreToAvailableRiskSlot
which in turn calls thefunction appendHrefWithRisks
.The
href
of the link button is passed through the methods and then appended on the successful addition of a risk to a label.Hopefully this helps someone else someday :)