0 Project
In my view I have a hidden filed which has a UserID
. This user id is generated upon an action (so this will not be know prior)
Once this
The answer provided by Darin is great and helped me, however as the comment suggests if you need to click the link again and pass a different value, how do you do that? This is a requirement if you are updating partial views etc. So here is how I achieved exactly that...
$(document).ready(function () {
$('#replyMessageButton').click(function () {
var url = $("#replyMessageButton").attr("href")
$("#replyMessageButton").attr("href", TrimToSlash(url) + $("#MessageId").val())
});
});
function TrimToSlash(value) {
if (value.indexOf("/") != -1) {
while (value.substr(-1) != '/') {
value = value.substr(0, value.length - 1);
}
}
return value;
}
@Ajax.ActionLink("Reply", "ReplyMessage", "MessageBox", new { id = -1 },
new AjaxOptions
{
UpdateTargetId = "replyMessageContainer",
InsertionMode = InsertionMode.Replace,
OnBegin = "UpdateDisplay('replyMessage')",
OnFailure = "UpdateDisplay('default')"
},
new { @id = "replyMessageButton" }
)
Also implemented is a check for messageId > 0 in the controller, hence why the id is initialized to -1. An "Error" view is returned if this condition is not met.